// File: /workspace/github_cpp_makefile_star2_O1/havluj[P]spreadsheet/src/CRuntime.cpp
// Function: CRuntime::run()
void CRuntime::run() {
    noecho();
    curs_set(0);

    int ch;
    int prevController = m_currentView;
    while (true) {
	  /* get the terminal dimensions */
	  getmaxyx(stdscr, m_terminalHeigth, m_terminalWidth);

	  /* make sure the terminal is large enough */
	  if (m_terminalWidth < 78 || m_terminalHeigth < 27) {
		if (m_currentView != SPLASHSCREEN_VIEW) {
		    prevController = m_currentView;
		}
		try {
		    changeView(SPLASHSCREEN_VIEW);
		} catch (const std::invalid_argument& e) {
		    throw e;
		}
	  } else {
		if (m_currentView == SPLASHSCREEN_VIEW) {
		    try {
			  changeView(prevController);
		    } catch (const std::invalid_argument& e) {
			  throw e;
		    }
		}
	  }

	  /* wait for a character to be pressed */
	  ch = getch();

	  switch (ch) {
		case KEY_F(4): // end the program
		    return;

		case KEY_RESIZE: // redraw the window
		    try {
			  changeView(m_currentView);
		    } catch (const std::invalid_argument& e) {
			  throw e;
		    }
		    break;

		case KEY_F(3): // show spreadsheet / help
		    if (m_currentView == TABLE_VIEW) {
			  try {
				changeView(HELP_VIEW);
			  } catch (const std::invalid_argument& e) {
				throw e;
			  }
		    } else {
			  try {
				changeView(TABLE_VIEW);
			  } catch (const std::invalid_argument& e) {
				throw e;
			  }
		    }
		    break;

		default:
		    m_controller->handleKey(ch);
		    break;
	  }
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0x4340
xorl %edi, %edi
callq 0x4270
movl 0x38(%rbx), %ebp
movq 0xa67f(%rip), %r14      # 0x12fb8
movq (%r14), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rdx, %rdx
je 0x8951
movswl 0x4(%rdx), %eax
incl %eax
movl %eax, 0x4c(%rbx)
testq %rdx, %rdx
je 0x895f
movswl 0x6(%rdx), %ecx
incl %ecx
movl %ecx, 0x48(%rbx)
movl 0x38(%rbx), %edx
cmpl $0x4e, %ecx
jl 0x897f
cmpl $0x1a, %eax
jle 0x897f
testl %edx, %edx
jne 0x898e
movq %rbx, %rdi
movl %ebp, %esi
callq 0x87f0
jmp 0x898e
testl %edx, %edx
cmovnel %edx, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x87f0
movq (%r14), %rdi
callq 0x40f0
cmpl $0x10b, %eax            # imm = 0x10B
je 0x89c9
cmpl $0x19a, %eax            # imm = 0x19A
je 0x89b9
cmpl $0x10c, %eax            # imm = 0x10C
je 0x89f3
movq 0x40(%rbx), %rdi
movq (%rdi), %rcx
movl %eax, %esi
callq *0x10(%rcx)
jmp 0x8939
movl 0x38(%rbx), %esi
movq %rbx, %rdi
callq 0x87f0
jmp 0x8939
cmpl $0x2, 0x38(%rbx)
jne 0x89e1
movq %rbx, %rdi
movl $0x3, %esi
callq 0x87f0
jmp 0x8939
movq %rbx, %rdi
movl $0x2, %esi
callq 0x87f0
jmp 0x8939
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8bdd
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movl $0x10, %edi
callq 0x4150
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4520
movq 0xa572(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa5a4(%rip), %rsi      # 0x12fe0
movq 0xa585(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8bd5
movq %rax, %rbx
callq 0x4510
jmp 0x8bdd
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8bdd
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movl $0x10, %edi
callq 0x4150
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4520
movq 0xa50d(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa53f(%rip), %rsi      # 0x12fe0
movq 0xa520(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8bd5
movq %rax, %rbx
callq 0x4510
jmp 0x8bdd
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8bdd
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movl $0x10, %edi
callq 0x4150
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4520
movq 0xa4a8(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa4da(%rip), %rsi      # 0x12fe0
movq 0xa4bb(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8bd5
movq %rax, %rbx
callq 0x4510
jmp 0x8bdd
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8bdd
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movl $0x10, %edi
callq 0x4150
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4520
movq 0xa443(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa475(%rip), %rsi      # 0x12fe0
movq 0xa456(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8bd5
movq %rax, %rbx
callq 0x4510
jmp 0x8bdd
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8bdd
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movl $0x10, %edi
callq 0x4150
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4520
movq 0xa3e8(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa41a(%rip), %rsi      # 0x12fe0
movq 0xa3fb(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
movq %rax, %rbx
callq 0x4510
movq %rbx, %rdi
callq 0x45a0
movq %rax, %rdi
callq 0x5314
nop