File size: 2,474 Bytes
8fd59af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from colorama import Style, Fore

import sys
import gradio as gr
import tty
import termios


def generate_progress_html(percent):
    return f"""
    <div class="progress-bar" style="width: 100%; background-color: #e0e0e0; border-radius: 10px; overflow: hidden; position: relative;">
        <div class="progress-bar-inner" style="height: 20px; background: linear-gradient(90deg, #76c7c0, #4ca1af); width: {percent}%; border-radius: 10px; transition: width 0.3s ease;">
            <div class="progress-text" style="position: absolute; width: 100%; top: 0; left: 0; height: 100%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: bold;">{percent}%</div>
        </div>
    </div>
    """

def get_char():
    """Read a single character from standard input without echo."""
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        char = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return char



def get_multiline_input():
    """Ask the human user_input till they press Ctrl+B."""
    print(Fore.BLUE + 'Enter your multiline text and press Ctrl+B when you are done:')
    user_input = []
    current_line = []
    line_num = 1
    
    print(f"{line_num}> ", end='', flush=True)
    
    while True:
        char = get_char()
        
        if ord(char) == 2:  # Ctrl+B
            break
        elif char == '\r' or char == '\n':  # Enter key
            line = ''.join(current_line)
            user_input.append(line)
            current_line = []
            line_num += 1
            print(f"\n{line_num}> ", end='', flush=True)
        elif char == '\x7f':  # Backspace
            if current_line:
                current_line.pop()
                # Move cursor back, overwrite with space, move back again
                print('\b \b', end='', flush=True)
        else:
            current_line.append(char)
            print(char, end='', flush=True)
    print('\n\n')
    return '\n'.join(user_input)



def system_update(update_message): 
    print(Style.RESET_ALL+ Fore.YELLOW  + f"{update_message}")

def system_sub_update(update_message): 
    print(Style.RESET_ALL+ Fore.CYAN  + f"{update_message}")

def system_output(update_message): 
    print(Style.RESET_ALL+ Fore.GREEN +  + f"{update_message}")

def system_error(update_message): 
    print(Style.RESET_ALL + Fore.RED + f"{update_message}")