// File: /workspace/github_cpp_makefile_star2_O1/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 0xae8d(%rip), %rax      # 0x17f30
cmpl $0xa, (%rax)
jl 0xd2d1
movq 0xae95(%rip), %r14      # 0x17f48
cmpl $0x28, (%r14)
jl 0xd2d1
leaq 0xb6dc(%rip), %rsi      # 0x187a0
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x9cde
movl 0x28(%rbx), %ebx
testl %ebx, %ebx
jle 0xd2c7
movl (%r14), %esi
addl $-0xa, %esi
movl %ebx, %edi
callq 0x62f0
movq %rax, %r14
leaq 0x20(%rsp), %r13
movq 0x10(%r13), %r15
cmpq %r13, %r15
je 0xd118
xorl %ecx, %ecx
movq %r15, %rax
movl 0x28(%rax), %ebp
cmpl %ebp, %ecx
cmovgl %ecx, %ebp
movq %rax, %rdi
callq 0x66a0
movl %ebp, %ecx
cmpq %r13, %rax
jne 0xd0ff
jmp 0xd11a
xorl %ebp, %ebp
testq %r14, %r14
movl %ebx, 0xc(%rsp)
je 0xd12c
movswl 0x6(%r14), %eax
incl %eax
jmp 0xd131
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subl %ebp, %eax
movl %eax, %ecx
addl $-0xa, %ecx
shrl $0x1f, %ecx
leal (%rax,%rcx), %r12d
addl $-0xa, %r12d
sarl %r12d
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
cmpq %r13, %r15
je 0xd18d
xorl %ebx, %ebx
movq 0x20(%r15), %r9
movq 0x40(%r15), %rax
movq %rax, (%rsp)
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
leaq 0x577d(%rip), %rcx      # 0x128ee
movl %ebp, %r8d
xorl %eax, %eax
callq 0x6150
incl %ebx
movq %r15, %rdi
callq 0x66a0
movq %rax, %r15
cmpq %r13, %rax
jne 0xd156
movq 0xad9c(%rip), %rax      # 0x17f30
movl (%rax), %r15d
leal -0xa(%r15), %edi
movq 0xada6(%rip), %rax      # 0x17f48
movslq (%rax), %rbx
leaq -0xa(%rbx), %r13
movl %r13d, %esi
movl $0x5, %edx
movl $0x5, %ecx
callq 0x65e0
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6b10
movabsq $0x1ffffffdd, %rbp      # imm = 0x1FFFFFFDD
leaq 0x1d(,%rbp), %rdx
addq %r13, %rdx
shrq %rdx
leaq 0x570c(%rip), %rcx      # 0x128f5
leaq 0x5498(%rip), %r8       # 0x12688
movq %r12, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x6150
leal -0xb(%r15), %esi
addq %rbp, %r13
shrq %r13
leaq 0x56e8(%rip), %rcx      # 0x128f5
leaq 0x547c(%rip), %r8       # 0x12690
movq %r12, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x6150
movq %r12, %rdi
callq 0x6670
movq %r12, 0x10(%rsp)
addl $-0x7, %ebx
movl 0xc(%rsp), %r12d
subl %r15d, %r12d
addl $-0x7, %r15d
addl $0xc, %r12d
xorl %ebp, %ebp
movq 0xad56(%rip), %r13      # 0x17fa0
movl %ebx, (%rsp)
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
movl $0x6, %ecx
movl $0x6, %r8d
movl %r15d, %r9d
callq 0x6630
movq (%r13), %rdi
callq 0x6240
cmpl $0x70, %eax
jle 0xd28a
cmpl $0x71, %eax
je 0xd2b1
cmpl $0x102, %eax            # imm = 0x102
je 0xd29f
cmpl $0x103, %eax            # imm = 0x103
je 0xd294
jmp 0xd2a9
cmpl $0x6a, %eax
je 0xd29f
cmpl $0x6b, %eax
jne 0xd2a9
xorl %eax, %eax
testl %ebp, %ebp
setg %al
subl %eax, %ebp
jmp 0xd2a9
xorl %eax, %eax
cmpl %r12d, %ebp
setl %al
addl %eax, %ebp
movb $0x1, %al
testb %al, %al
jne 0xd24a
jmp 0xd2b5
xorl %eax, %eax
jmp 0xd2ab
movq 0x10(%rsp), %rdi
callq 0x60b0
movq %r14, %rdi
callq 0x60b0
leaq 0x18(%rsp), %rdi
callq 0xaf56
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd2ea
jmp 0xd2ea
jmp 0xd2ea
jmp 0xd2ea
jmp 0xd2ea
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xaf56
movq %rbx, %rdi
callq 0x6a80
nop