// File: Linkerist[P]xs/src/ui.cc
// Function: user_interaction(int)
bool
user_interaction(int c)
{
 int num;
 string curen;

 switch (c) {
  // ==== Exits
  case CTRL('['): // vi
  case CTRL('g'): // emacs
   abort_xs();
   break;
  case 'q':
   finish(".", false);
   break;
  case 13: // ENTER
   // choose dir at cur pos
   return false;
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
   num =  c - '0' + shorties_offset;
   if(mode == LIST) {
	if (entry_nr_exists(num)) {
	 CurrPosition = num + yoffset;
	 return opt_no_resolve;
	}
   } else {
	CurrPosition = num + yoffset;
	return true;
   }
   break;

  // ==== Modes
  case '.':
   // show hidden files
   toggle_hidden();
   break;
  case '\t': // TAB
   toggle_mode();
   break;      

  // ==== Navigate The List
#if TERMINFO
  case KEY_DOWN:
#endif
   // navigate list++
   cur_pos_adjust(+1);
   break;

#if TERMINFO
  case KEY_UP:
#endif
   // navigate list--
   cur_pos_adjust(-1);
   break;

  case '^':       // vi?
  case CTRL('a'): // emacs
#if TERMINFO
  case KEY_HOME:
#endif
   // go to top
   CurrPosition = 0;
   yoffset = 0;
   break;

# if TERMINFO
  case KEY_END:
#endif
   // go to end
   if (mode == BROWSE)
	CurrPosition = cur_list.size() - 1;
   else if (mode == LIST)
	CurrPosition = default_list.size() - 1;

   yoffset = max_yoffset();
   break;

  //==== move the shortcut digits ('shorties')
  // FIXME maybe change the scrolling behaviour to not take the window but the whole
  // list? That means recentering when shorties leave the screen (adjust yoffset and
  // CurrPosition) 
#if TERMINFO      
  case KEY_NPAGE:
#endif
   for(int i = 0; i < 10; i++)
	cur_pos_adjust(+1, false);
   break;

#if TERMINFO
  case KEY_PPAGE:
#endif
   for(int i = 0; i < 10; i++)
	cur_pos_adjust(-1, false);
   break;

#if TERMINFO
  case KEY_LEFT:
#endif
   // up dir
   if (mode == BROWSE)
	//             LastPositions[get_current_dir_name()] = CurrPosition;
	LastPositions[get_cwd_as_charp()] = CurrPosition;
   else if (mode == LIST)
	mode = BROWSE;

   list_from_dir("..");
   break;

#if TERMINFO
  case KEY_RIGHT:
#endif
   // descend dir at cur pos
   curen = current_entry();
   if (mode == BROWSE)
	LastPositions[get_cwd_as_charp()] = CurrPosition;
   else
	mode = BROWSE;

   list_from_dir(curen.c_str());
   break;

  case '?':
   helpscreen();
   break;

#if TERMINFO
  case KEY_BACKSPACE:
#endif
   // delete dir acp
   if (mode == LIST && !NeedleGiven)
	delete_from_default_list(CurrPosition);
   else
	beep();

   break;

  #if TERMINFO
  case KEY_IC:
  #endif
  case 'a':
   // add dir acp (if in browse mode)
   if (!NeedleGiven) {
	if (mode == BROWSE)
	 add_to_default_list(current_entry());
	else
	 add_to_default_list(get_cwd_as_string());
   } else
	beep();

   break;

  case 'A':
   if (!NeedleGiven) {
	// add dir acp (if in browse mode) (ask for desc)
	if (mode == BROWSE)
	 add_to_default_list(current_entry(),"",true);
	else
	 add_to_default_list(get_cwd_as_string(),"",true);
   } else
	beep();

   break;
  case 'c':
   if (!NeedleGiven)
	// add the current dir in every mode
	add_to_default_list(get_cwd_as_string());
   else
	beep();

   break;
  case 'C':
   if (!NeedleGiven)
	// add the current dir in every mode (ask for desc)
	add_to_default_list(get_cwd_as_string(), "", true);
   else
	beep();

   break;

  // ==== EDIT the list
  case 'v':
  case 'e':
   if (!NeedleGiven)
	edit_list_file();
   else
	beep();

   break;

  case 'm':
   swap_two_entries(1);
   break;
  case 'M':
   swap_two_entries(-1);
   break;
  case 't':
  case 's':
   swap_two_entries(0);
   break;

  // ==== Filesystem Hotspots
  case '~':
   mode = BROWSE;
   list_from_dir(getenv("HOME"));
   break;
  case '/':
   mode = BROWSE;
   list_from_dir("/");
   break;
  default:
   beep();
   message("unknown command");
 }
 return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movl %edi, -0x8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4590
movl -0x8(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x258(%rbp)
subl $0x167, %eax            # imm = 0x167
ja 0xd37d
movq -0x258(%rbp), %rax
leaq 0x3dd6(%rip), %rcx      # 0x107c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x50f0
jmp 0xc9fe
jmp 0xd394
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xd3b6
leaq -0x61(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x4740
movq -0x260(%rbp), %rdx
leaq 0x3766(%rip), %rsi      # 0x10198
leaq -0x60(%rbp), %rdi
callq 0x5e40
jmp 0xca3d
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
callq 0x53d0
jmp 0xca4a
leaq -0x60(%rbp), %rdi
callq 0x4828
leaq -0x61(%rbp), %rdi
callq 0x4450
jmp 0xd394
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xca84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4828
leaq -0x61(%rbp), %rdi
callq 0x4450
jmp 0xd3b6
movb $0x0, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0xd39f
movl -0x8(%rbp), %eax
subl $0x30, %eax
addl 0xab86(%rip), %eax      # 0x17634
movl %eax, -0xc(%rbp)
leaq 0xaae0(%rip), %rax      # 0x17598
cmpl $0x0, (%rax)
jne 0xcb07
movl -0xc(%rbp), %edi
callq 0x8170
movb %al, -0x261(%rbp)
jmp 0xcacd
movb -0x261(%rbp), %al
testb $0x1, %al
jne 0xcad9
jmp 0xcb05
movl -0xc(%rbp), %ecx
addl 0xab4a(%rip), %ecx      # 0x1762c
leaq 0xaa7b(%rip), %rax      # 0x17564
movl %ecx, (%rax)
leaq 0xaaac(%rip), %rax      # 0x1759e
movb (%rax), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0xd39f
jmp 0xcb29
movl -0xc(%rbp), %ecx
addl 0xab1c(%rip), %ecx      # 0x1762c
leaq 0xaa4d(%rip), %rax      # 0x17564
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0xd39f
jmp 0xd394
callq 0x57a0
jmp 0xcb35
jmp 0xd394
callq 0xd3d0
jmp 0xcb41
jmp 0xd394
movl $0x1, %esi
movl %esi, %edi
callq 0x8030
jmp 0xcb54
jmp 0xd394
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x1, %esi
callq 0x8030
jmp 0xcb6a
jmp 0xd394
leaq 0xa9ee(%rip), %rax      # 0x17564
movl $0x0, (%rax)
movl $0x0, 0xaaa6(%rip)      # 0x1762c
jmp 0xd394
leaq 0xaa06(%rip), %rax      # 0x17598
cmpl $0x1, (%rax)
jne 0xcbb4
leaq 0xa98a(%rip), %rdi      # 0x17528
callq 0x61f0
subq $0x1, %rax
movl %eax, %ecx
leaq 0xa9b4(%rip), %rax      # 0x17564
movl %ecx, (%rax)
jmp 0xcbdd
leaq 0xa9dd(%rip), %rax      # 0x17598
cmpl $0x0, (%rax)
jne 0xcbdb
leaq 0xa979(%rip), %rdi      # 0x17540
callq 0x61f0
subq $0x1, %rax
movl %eax, %ecx
leaq 0xa98b(%rip), %rax      # 0x17564
movl %ecx, (%rax)
jmp 0xcbdd
callq 0x57d0
movl %eax, -0x268(%rbp)
jmp 0xcbea
movl -0x268(%rbp), %eax
movl %eax, 0xaa36(%rip)      # 0x1762c
jmp 0xd394
movl $0x0, -0x6c(%rbp)
cmpl $0xa, -0x6c(%rbp)
jge 0xcc23
movl $0x1, %edi
xorl %esi, %esi
callq 0x8030
jmp 0xcc16
jmp 0xcc18
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xcc02
jmp 0xd394
movl $0x0, -0x70(%rbp)
cmpl $0xa, -0x70(%rbp)
jge 0xcc50
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
callq 0x8030
jmp 0xcc43
jmp 0xcc45
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0xcc2f
jmp 0xd394
leaq 0xa93c(%rip), %rax      # 0x17598
cmpl $0x1, (%rax)
jne 0xccb3
leaq 0xa8fc(%rip), %rax      # 0x17564
movl (%rax), %eax
movl %eax, -0x274(%rbp)
callq 0x5120
movq %rax, -0x270(%rbp)
jmp 0xcc7e
movq -0x270(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq 0xa8d8(%rip), %rdi      # 0x17568
leaq -0x78(%rbp), %rsi
callq 0x8ce0
movq %rax, -0x280(%rbp)
jmp 0xcca2
movq -0x280(%rbp), %rax
movl -0x274(%rbp), %ecx
movl %ecx, (%rax)
jmp 0xccce
leaq 0xa8de(%rip), %rax      # 0x17598
cmpl $0x0, (%rax)
jne 0xcccc
leaq 0xa8d2(%rip), %rax      # 0x17598
movl $0x1, (%rax)
jmp 0xccce
leaq 0x34c2(%rip), %rdi      # 0x10197
callq 0x7250
jmp 0xccdc
jmp 0xd394
leaq -0x98(%rbp), %rdi
callq 0x8200
jmp 0xccef
leaq -0x30(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x44f0
leaq -0x98(%rbp), %rdi
callq 0x4828
leaq 0xa886(%rip), %rax      # 0x17598
cmpl $0x1, (%rax)
jne 0xcd6f
leaq 0xa846(%rip), %rax      # 0x17564
movl (%rax), %eax
movl %eax, -0x28c(%rbp)
callq 0x5120
movq %rax, -0x288(%rbp)
jmp 0xcd34
movq -0x288(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq 0xa81f(%rip), %rdi      # 0x17568
leaq -0xa0(%rbp), %rsi
callq 0x8ce0
movq %rax, -0x298(%rbp)
jmp 0xcd5e
movq -0x298(%rbp), %rax
movl -0x28c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0xcd7c
leaq 0xa822(%rip), %rax      # 0x17598
movl $0x1, (%rax)
leaq -0x30(%rbp), %rdi
callq 0x41a0
movq %rax, %rdi
callq 0x7250
jmp 0xcd8f
jmp 0xd394
callq 0xd4b0
jmp 0xcd9b
jmp 0xd394
leaq 0xa7f1(%rip), %rax      # 0x17598
cmpl $0x0, (%rax)
jne 0xcdca
leaq 0xa7ad(%rip), %rax      # 0x17560
testb $0x1, (%rax)
jne 0xcdca
leaq 0xa7a5(%rip), %rax      # 0x17564
movl (%rax), %edi
callq 0x8720
jmp 0xcdc8
jmp 0xcdd3
callq 0x40c0
jmp 0xcdd1
jmp 0xcdd3
jmp 0xd394
leaq 0xa781(%rip), %rax      # 0x17560
testb $0x1, (%rax)
jne 0xcf77
leaq 0xa7a9(%rip), %rax      # 0x17598
cmpl $0x1, (%rax)
jne 0xceb8
leaq -0xc0(%rbp), %rdi
callq 0x8200
jmp 0xce06
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x4740
movq -0x2a0(%rbp), %rdx
leaq 0x3553(%rip), %rsi      # 0x1037a
leaq -0xe0(%rbp), %rdi
callq 0x5e40
jmp 0xce35
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
xorl %edx, %edx
callq 0x8440
jmp 0xce4c
leaq -0xe0(%rbp), %rdi
callq 0x4828
leaq -0xe1(%rbp), %rdi
callq 0x4450
leaq -0xc0(%rbp), %rdi
callq 0x4828
jmp 0xcf75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xce9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x4828
leaq -0xe1(%rbp), %rdi
callq 0x4450
leaq -0xc0(%rbp), %rdi
callq 0x4828
jmp 0xd3b6
leaq -0x108(%rbp), %rdi
callq 0x51b0
jmp 0xcec6
leaq -0x129(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x4740
movq -0x2a8(%rbp), %rdx
leaq 0x3493(%rip), %rsi      # 0x1037a
leaq -0x128(%rbp), %rdi
callq 0x5e40
jmp 0xcef5
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
xorl %edx, %edx
callq 0x8440
jmp 0xcf0c
leaq -0x128(%rbp), %rdi
callq 0x4828
leaq -0x129(%rbp), %rdi
callq 0x4450
leaq -0x108(%rbp), %rdi
callq 0x4828
jmp 0xcf75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xcf58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x4828
leaq -0x129(%rbp), %rdi
callq 0x4450
leaq -0x108(%rbp), %rdi
callq 0x4828
jmp 0xd3b6
jmp 0xcf80
callq 0x40c0
jmp 0xcf7e
jmp 0xcf80
jmp 0xd394
leaq 0xa5d4(%rip), %rax      # 0x17560
testb $0x1, (%rax)
jne 0xd12a
leaq 0xa5fc(%rip), %rax      # 0x17598
cmpl $0x1, (%rax)
jne 0xd068
leaq -0x150(%rbp), %rdi
callq 0x8200
jmp 0xcfb3
leaq -0x171(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x4740
movq -0x2b0(%rbp), %rdx
leaq 0x33a6(%rip), %rsi      # 0x1037a
leaq -0x170(%rbp), %rdi
callq 0x5e40
jmp 0xcfe2
leaq -0x150(%rbp), %rdi
leaq -0x170(%rbp), %rsi
movl $0x1, %edx
callq 0x8440
jmp 0xcffc
leaq -0x170(%rbp), %rdi
callq 0x4828
leaq -0x171(%rbp), %rdi
callq 0x4450
leaq -0x150(%rbp), %rdi
callq 0x4828
jmp 0xd128
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xd04b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x4828
leaq -0x171(%rbp), %rdi
callq 0x4450
leaq -0x150(%rbp), %rdi
callq 0x4828
jmp 0xd3b6
leaq -0x198(%rbp), %rdi
callq 0x51b0
jmp 0xd076
leaq -0x1b9(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x4740
movq -0x2b8(%rbp), %rdx
leaq 0x32e3(%rip), %rsi      # 0x1037a
leaq -0x1b8(%rbp), %rdi
callq 0x5e40
jmp 0xd0a5
leaq -0x198(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
movl $0x1, %edx
callq 0x8440
jmp 0xd0bf
leaq -0x1b8(%rbp), %rdi
callq 0x4828
leaq -0x1b9(%rbp), %rdi
callq 0x4450
leaq -0x198(%rbp), %rdi
callq 0x4828
jmp 0xd128
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xd10b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x4828
leaq -0x1b9(%rbp), %rdi
callq 0x4450
leaq -0x198(%rbp), %rdi
callq 0x4828
jmp 0xd3b6
jmp 0xd133
callq 0x40c0
jmp 0xd131
jmp 0xd133
jmp 0xd394
leaq 0xa421(%rip), %rax      # 0x17560
testb $0x1, (%rax)
jne 0xd205
leaq -0x1e0(%rbp), %rdi
callq 0x51b0
jmp 0xd156
leaq -0x201(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x4740
movq -0x2c0(%rbp), %rdx
leaq 0x3203(%rip), %rsi      # 0x1037a
leaq -0x200(%rbp), %rdi
callq 0x5e40
jmp 0xd185
leaq -0x1e0(%rbp), %rdi
leaq -0x200(%rbp), %rsi
xorl %edx, %edx
callq 0x8440
jmp 0xd19c
leaq -0x200(%rbp), %rdi
callq 0x4828
leaq -0x201(%rbp), %rdi
callq 0x4450
leaq -0x1e0(%rbp), %rdi
callq 0x4828
jmp 0xd20e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xd1e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x4828
leaq -0x201(%rbp), %rdi
callq 0x4450
leaq -0x1e0(%rbp), %rdi
callq 0x4828
jmp 0xd3b6
callq 0x40c0
jmp 0xd20c
jmp 0xd20e
jmp 0xd394
leaq 0xa346(%rip), %rax      # 0x17560
testb $0x1, (%rax)
jne 0xd2e3
leaq -0x228(%rbp), %rdi
callq 0x51b0
jmp 0xd231
leaq -0x249(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x4740
movq -0x2c8(%rbp), %rdx
leaq 0x3128(%rip), %rsi      # 0x1037a
leaq -0x248(%rbp), %rdi
callq 0x5e40
jmp 0xd260
leaq -0x228(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movl $0x1, %edx
callq 0x8440
jmp 0xd27a
leaq -0x248(%rbp), %rdi
callq 0x4828
leaq -0x249(%rbp), %rdi
callq 0x4450
leaq -0x228(%rbp), %rdi
callq 0x4828
jmp 0xd2ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xd2c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x4828
leaq -0x249(%rbp), %rdi
callq 0x4450
leaq -0x228(%rbp), %rdi
callq 0x4828
jmp 0xd3b6
callq 0x40c0
jmp 0xd2ea
jmp 0xd2ec
jmp 0xd394
leaq 0xa268(%rip), %rax      # 0x17560
testb $0x1, (%rax)
jne 0xd306
callq 0x87c0
jmp 0xd304
jmp 0xd30f
callq 0x40c0
jmp 0xd30d
jmp 0xd30f
jmp 0xd394
movl $0x1, %edi
callq 0xe650
jmp 0xd320
jmp 0xd394
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xe650
jmp 0xd32e
jmp 0xd394
xorl %edi, %edi
callq 0xe650
jmp 0xd339
jmp 0xd394
leaq 0xa256(%rip), %rax      # 0x17598
movl $0x1, (%rax)
leaq 0x2ccf(%rip), %rdi      # 0x1001e
callq 0x44e0
movq %rax, %rdi
callq 0x7250
jmp 0xd35e
jmp 0xd394
leaq 0xa231(%rip), %rax      # 0x17598
movl $0x1, (%rax)
leaq 0x2ca8(%rip), %rdi      # 0x1001c
callq 0x7250
jmp 0xd37b
jmp 0xd394
callq 0x40c0
jmp 0xd384
leaq 0x39d9(%rip), %rdi      # 0x10d64
callq 0xe7a0
jmp 0xd392
jmp 0xd394
movb $0x1, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4828
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x4828
movq -0x38(%rbp), %rdi
callq 0x4730
nopl (%rax,%rax)