// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
callq 0x4370
xorl %edi, %edi
callq 0x42a0
movl 0x38(%rbx), %ebp
movq 0xaea5(%rip), %r12      # 0x12fb8
pushq $0x3
popq %r14
pushq $0x2
popq %r15
movq (%r12), %rax
testq %rax, %rax
je 0x8160
movzwl 0x4(%rax), %ecx
movswl %cx, %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x4c(%rbx)
movswl 0x6(%rax), %eax
cmpl $0x4d, %eax
setl %dl
incl %eax
cmpw $0x1a, %cx
setl %cl
movl %eax, 0x48(%rbx)
orb %dl, %cl
cmpb $0x1, %cl
je 0x8165
cmpl $0x0, 0x38(%rbx)
jne 0x8177
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7ff2
jmp 0x8177
orq $-0x1, 0x48(%rbx)
movl 0x38(%rbx), %eax
testl %eax, %eax
cmovnel %eax, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7ff2
movq (%r12), %rdi
callq 0x4100
cmpl $0x10b, %eax            # imm = 0x10B
je 0x81b6
cmpl $0x19a, %eax            # imm = 0x19A
je 0x81a6
cmpl $0x10c, %eax            # imm = 0x10C
je 0x81dc
movq 0x40(%rbx), %rdi
movq (%rdi), %rcx
movl %eax, %esi
callq *0x10(%rcx)
jmp 0x811b
movl 0x38(%rbx), %esi
movq %rbx, %rdi
callq 0x7ff2
jmp 0x811b
cmpl $0x2, 0x38(%rbx)
jne 0x81cc
movq %rbx, %rdi
movl %r14d, %esi
callq 0x7ff2
jmp 0x811b
movq %rbx, %rdi
movl %r15d, %esi
callq 0x7ff2
jmp 0x811b
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x837a
movq %rbx, %rdi
callq 0x4120
movq %rax, %rbx
pushq $0x10
popq %rdi
callq 0x4180
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x838a
movq 0xadc7(%rip), %rsi      # 0x12fe0
movq 0xada8(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8372
movq %rax, %rbx
callq 0x4520
jmp 0x837a
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x837a
movq %rbx, %rdi
callq 0x4120
movq %rax, %rbx
pushq $0x10
popq %rdi
callq 0x4180
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x838a
movq 0xad72(%rip), %rsi      # 0x12fe0
movq 0xad53(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8372
movq %rax, %rbx
callq 0x4520
jmp 0x837a
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x837a
movq %rbx, %rdi
callq 0x4120
movq %rax, %rbx
pushq $0x10
popq %rdi
callq 0x4180
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x838a
movq 0xad1d(%rip), %rsi      # 0x12fe0
movq 0xacfe(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8372
movq %rax, %rbx
callq 0x4520
jmp 0x837a
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x837a
movq %rbx, %rdi
callq 0x4120
movq %rax, %rbx
pushq $0x10
popq %rdi
callq 0x4180
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x838a
movq 0xacc8(%rip), %rsi      # 0x12fe0
movq 0xaca9(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8372
movq %rax, %rbx
callq 0x4520
jmp 0x837a
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x837a
movq %rbx, %rdi
callq 0x4120
movq %rax, %rbx
pushq $0x10
popq %rdi
callq 0x4180
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x838a
movq 0xac7d(%rip), %rsi      # 0x12fe0
movq 0xac5e(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
movq %rax, %rbx
callq 0x4520
movq %rbx, %rdi
callq 0x4590
movq %rax, %rdi
callq 0x535e