// File: /workspace/github_cpp_makefile_star2_O2/fulhax[P]ncpamixer/src/ui/ui.cpp
// Function: Ui::show_help()
void Ui::show_help() {
    if (LINES < 10) return;
    if (COLS < 40) return;

    // Create a new pad. The size of the pad is defined by HELP_LINES.
    const auto& c { config.getKeycodeNameEvents() };
    const auto HELP_LINES = static_cast<int>(c.size());
    if (HELP_LINES < 1) return; // No help to show :(
    WINDOW *pad = newpad(HELP_LINES, COLS - 10);

    // Add some text to the pad
    int line = 0;
    //  max_length left-justifies the string and pads it with spaces to the right, ensuring 
    //  that the equals sign always appears at the same position
    int max_length = 0;
    for (const auto& it : c) {
        max_length = std::max(max_length, static_cast<int>(it.first.length()));
    }

    int start_pos = (getmaxx(pad) - (max_length + 10)) / 2; // 10 is an arbitrary number
    if (start_pos < 0) start_pos = 0; // Ensure start_pos is not negative
    for (const auto& it : c) {
        mvwprintw(pad, line++, start_pos,  "%-*s = %s", max_length, it.first.c_str(), it.second.c_str());
    }

    // Calculate the size and position of the window
    int window_height = LINES - 10;
    int window_width = COLS - 10;
    int window_top = (LINES - window_height) / 2;
    int window_left = (COLS - window_width) / 2;

    // Create a new window to display the pad
    WINDOW *win = newwin(window_height, window_width, window_top, window_left);
    box(win, 0, 0);

    // Add a title and a footer to the window
    mvwprintw(win, 0, (window_width - HELP_HEADER_SIZE) / 2, "%s", HELP_HEADER);
    mvwprintw(win, window_height - 1, (window_width - HELP_FOOTER_SIZE) / 2, "%s", HELP_FOOTER);

    wrefresh(win);

    int pad_top_line = 0;

    // Main loop
    while (true) {
        // Display the pad in the window
        prefresh(pad, pad_top_line, 0, window_top + 1, window_left + 1, window_top + window_height - 2, window_left + window_width - 2);

        // Wait for user input
        int ch = getch();
        if (ch == KEY_UP || ch == 'k') {
            // Up arrow key pressed. Check if the top of the pad is reached.
            if (pad_top_line > 0) {
                --pad_top_line;
            }
        } else if (ch == KEY_DOWN || ch == 'j') {
            // Down arrow key pressed. Check if the bottom of the pad is reached.
            if (pad_top_line < HELP_LINES - (window_height - 2)) {
                ++pad_top_line;
            }
        } else if (ch == 'q') {
            // 'q' key pressed. Exit the loop.
            break;
        }
    }

    // Delete the window and the pad
    delwin(win);
    delwin(pad);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq 0xbd7b(%rip), %rax      # 0x17f20
cmpl $0xa, (%rax)
jl 0xc3ae
movq 0xbd83(%rip), %r14      # 0x17f38
cmpl $0x28, (%r14)
jl 0xc3ae
leaq 0xc60a(%rip), %rsi      # 0x187d0
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x97fa
movl 0x28(%rbx), %ebx
testl %ebx, %ebx
jle 0xc3a4
movl (%r14), %esi
addl $-0xa, %esi
movl %ebx, %edi
callq 0x62f0
movq %rax, %r12
leaq 0x20(%rsp), %r14
movq 0x10(%r14), %r15
xorl %ebp, %ebp
movq %r15, %rax
cmpq %r14, %rax
je 0xc213
movl 0x28(%rax), %ecx
cmpl %ecx, %ebp
cmovlel %ecx, %ebp
movq %rax, %rdi
callq 0x66b0
jmp 0xc1fc
testq %r12, %r12
movl %ebx, 0xc(%rsp)
movq %r12, 0x10(%rsp)
je 0xc22b
movswl 0x6(%r12), %eax
incl %eax
jmp 0xc22e
pushq $-0x1
popq %rax
subl %ebp, %eax
addl $-0xa, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, %r12d
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
leaq 0x56e2(%rip), %r13      # 0x1192e
xorl %ebx, %ebx
cmpq %r14, %r15
je 0xc285
movq 0x20(%r15), %r9
movq 0x40(%r15), %rax
movq %rax, (%rsp)
movq 0x10(%rsp), %rdi
movl %ebx, %esi
movl %r12d, %edx
movq %r13, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x6150
incl %ebx
movq %r15, %rdi
callq 0x66b0
movq %rax, %r15
jmp 0xc24e
movq 0xbc94(%rip), %rax      # 0x17f20
movl (%rax), %r15d
leal -0xa(%r15), %edi
movq 0xbc9e(%rip), %rax      # 0x17f38
movslq (%rax), %rbx
leaq -0xa(%rbx), %r13
pushq $0x5
popq %rcx
movl %r13d, %esi
movl %ecx, %edx
callq 0x6600
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6b50
movabsq $0x1ffffffdd, %r14      # imm = 0x1FFFFFFDD
leaq (%r14,%r13), %rdx
addq $0x1d, %rdx
shrq %rdx
leaq 0x565c(%rip), %rcx      # 0x11935
leaq 0x53e0(%rip), %r8       # 0x116c0
movq %r12, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x6150
leal -0xb(%r15), %esi
addq %r14, %r13
shrq %r13
leaq 0x5638(%rip), %rcx      # 0x11935
leaq 0x53cc(%rip), %r8       # 0x116d0
movq %r12, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x6150
movq %r12, %rdi
callq 0x6680
addl $-0x7, %ebx
movl 0xc(%rsp), %eax
subl %r15d, %eax
addl $-0x7, %r15d
addl $0xc, %eax
movl %eax, 0xc(%rsp)
xorl %ebp, %ebp
pushq $0x6
popq %r13
movq 0xbc55(%rip), %r14      # 0x17f90
movl %ebx, (%rsp)
movq 0x10(%rsp), %rdi
movl %ebp, %esi
xorl %edx, %edx
movl %r13d, %ecx
movl %r13d, %r8d
movl %r15d, %r9d
callq 0x6650
movq (%r14), %rdi
callq 0x6230
cmpl $0x6a, %eax
je 0xc385
cmpl $0x103, %eax            # imm = 0x103
je 0xc37a
cmpl $0x71, %eax
je 0xc392
cmpl $0x102, %eax            # imm = 0x102
je 0xc385
cmpl $0x6b, %eax
jne 0xc33b
xorl %eax, %eax
testl %ebp, %ebp
setg %al
negl %eax
jmp 0xc38e
xorl %eax, %eax
cmpl 0xc(%rsp), %ebp
setl %al
addl %eax, %ebp
jmp 0xc33b
movq %r12, %rdi
callq 0x60b0
movq 0x10(%rsp), %rdi
callq 0x60b0
leaq 0x18(%rsp), %rdi
callq 0xa9aa
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc3c7
jmp 0xc3c7
jmp 0xc3c7
jmp 0xc3c7
jmp 0xc3c7
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xa9aa
movq %rbx, %rdi
callq 0x6ac0