// File: /workspace/github_cpp_makefile_star2_O3/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 0xa707(%rip), %r14      # 0x12fb8
movq (%r14), %rax
testq %rax, %rax
je 0x88f6
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
movl %eax, 0x48(%rbx)
cmpw $0x1a, %cx
setl %cl
orb %dl, %cl
movl 0x38(%rbx), %eax
cmpb $0x1, %cl
je 0x8901
testl %eax, %eax
jne 0x8910
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8778
jmp 0x8910
movq $-0x1, 0x48(%rbx)
movl 0x38(%rbx), %eax
testl %eax, %eax
cmovnel %eax, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8778
movq (%r14), %rdi
callq 0x40f0
cmpl $0x10b, %eax            # imm = 0x10B
je 0x894e
cmpl $0x19a, %eax            # imm = 0x19A
je 0x893e
cmpl $0x10c, %eax            # imm = 0x10C
je 0x8978
movq 0x40(%rbx), %rdi
movq (%rdi), %rcx
movl %eax, %esi
callq *0x10(%rcx)
jmp 0x88b1
movl 0x38(%rbx), %esi
movq %rbx, %rdi
callq 0x8778
jmp 0x88b1
cmpl $0x2, 0x38(%rbx)
jne 0x8966
movq %rbx, %rdi
movl $0x3, %esi
callq 0x8778
jmp 0x88b1
movq %rbx, %rdi
movl $0x2, %esi
callq 0x8778
jmp 0x88b1
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8b62
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 0xa5ed(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa61f(%rip), %rsi      # 0x12fe0
movq 0xa600(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8b5a
movq %rax, %rbx
callq 0x4510
jmp 0x8b62
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8b62
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 0xa588(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa5ba(%rip), %rsi      # 0x12fe0
movq 0xa59b(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8b5a
movq %rax, %rbx
callq 0x4510
jmp 0x8b62
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8b62
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 0xa523(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa555(%rip), %rsi      # 0x12fe0
movq 0xa536(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8b5a
movq %rax, %rbx
callq 0x4510
jmp 0x8b62
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8b62
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 0xa4be(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa4f0(%rip), %rsi      # 0x12fe0
movq 0xa4d1(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
jmp 0x8b5a
movq %rax, %rbx
callq 0x4510
jmp 0x8b62
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8b62
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 0xa463(%rip), %rax      # 0x12fa0
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa495(%rip), %rsi      # 0x12fe0
movq 0xa476(%rip), %rdx      # 0x12fc8
movq %r14, %rdi
callq 0x4560
movq %rax, %rbx
callq 0x4510
movq %rbx, %rdi
callq 0x45a0
movq %rax, %rdi
callq 0x5314