def keygen(): #VARIBALES ShowHelp = True EmptyKeyboard = True print("\033[2J") #keychoosed = input("Choose Default keyoard: ") x, y = 0, 0 while True: print("\033[2J") print("\033[1;1H" + (lambda EmptyKeyboard: keyboard_empty if EmptyKeyboard else keyboard)(EmptyKeyboard)) print(f"\033[{1};{18}H{x = }, {y = }") if ShowHelp: current = printposkey(x, y) if current: print(f"\033[{1};{40}H{current=}") key = getKey(debug=True) if key == "h": ShowHelp = not ShowHelp elif key == "k": EmptyKeyboard = not EmptyKeyboard elif key == "\x1b[A": # UP x += 1 elif key == "\x1b[B": # DOWN x -= 1 elif key == "\x1b[C": # RIGHT y += 1 elif key == "\x1b[D": # LEFT y -= 1
def printontermnal(to_printfile, boucle=True): ShowLines = False Firstline = 0 ChosedLink = 0 Reapet = True while Reapet: for i in to_printfile: print(i) if boucle: key = getKey(debug=True) if key == "l": ShowLines = not ShowLines if key == "j": # DOWN Firstline = Firstline + 1 # min(Firstline+1, len(to_printfile)) if key == "k": # Up Firstline = Firstline - 1 # max(Firstline-1, 0) if key == "Tab": ChosedLink = ChosedLink + 1 # min(ChosedLink+1, len(alllink)) if key == "ShiftTab": ChosedLink = ChosedLink - 1 # min(ChosedLink-1, 0) if key == "\r": #ENTER pass # TODO: Open browser with current link else: Reapet = False
def Shellmain(): normalMode = ShellModes(0, "Normal", []) insertMode = ShellModes(1, "Insert", []) ReplaceMode = ShellModes(2, "Replace", []) CommandMode = ShellModes(3, "Command", []) clear() ShellDraw.reload_all() while True: key = getKey(debug=True) sys.stdout.write("\033[0;0H") # print(get_key_bytes(True)) if ShellModes.currentMode == 0: # Normal Mode ShellModes.all_mode(key) ShellModes.normal_mode(key) ShellModes.normal_insert_mode(key) elif ShellModes.currentMode == 1: ShellModes.all_mode(key) ShellModes.insert_mode(key) ShellModes.normal_insert_mode(key) elif ShellModes.currentMode == 2: ShellModes.all_mode(key) elif ShellModes.currentMode == 3: ShellModes.all_mode(key) ShellDraw.cursor_key() sys.stdout.flush()
def _getkey(self): i = 0 while not self.stopping: i += 1 print(f"\033[13;13H{i}{self.stopping}") key = getKey() if key == "a": print("\033[5;5HHe press A") elif key == "q" or key == "\x03": clean_quit()
def inputbar(before=""): chaine = "" InputOpen = True while InputOpen: key = getKey(debug=True) if key == '\x7f': chaine = chaine[:-1] elif key == '\x1b\x1b' or key == "\r": return chaine elif key in "azertyuiopqsdfghjklmwxcvbn AZERTYUIOPQSDFGHJKLMWXCVBN_1234567890": chaine += key print(before + chaine)
def clilaunch(): """ # TODO, Apps a faire: autoreadme, compressint, countligne, ?duplicateFile, keyboardGenerator, minesweeper, readmereader, getbyteskey, tetris """ from main_terminalGetKey import getKey global current_menu # 0 = Normal, 1=CountLine, current_menu = 0 # 0 = Normal, 1=CountLine, Apps_to_launch = [{ '0': ('demineur', lambda: demineur()), '1': ('menu count ligne', lambda: change_current_menu(1)) }, { '0': ('print ok', lambda: print("ok")), '1': ('print okj2', lambda: print('ojk2')) }] while True: # TODO Afficher les aides key = getKey(debug=True) if key in Apps_to_launch[current_menu]: clear() Apps_to_launch[current_menu][key][1]() else: print("Commande Inconnue") print(current_menu)
def demineur(size: int = 10): game_open = True drapeau_map = [[False for j in range(size)] for i in range(size)] plateau = [] for i in range(size): ligne = [] for j in range(size): if randint(1, 10) >= 3: ligne += [10] else: ligne += [9] plateau += [ligne] nouveau_plateau = [] for i in range(len(plateau)): ligne = [] for j in range(len(plateau[i])): if plateau[i][j] == 9: ligne += [9] else: somme = 0 for k in range(-1, 2): for l in range(-1, 2): if not (k == 0 and l == 0): if 0 <= i + k < 10 and 0 <= j + l < 10: if plateau[i + k][j + l] == 9: somme += 1 if somme == 0: ligne += [10] else: ligne += [-somme] nouveau_plateau += [ligne] del ligne plateau = nouveau_plateau # Plateau = [[0 if randint(1,10) >= 2 else -1 for j in range(size)] for i in range(size)] # Cache = [[1 for j in range(size)] for i in range(size)] x, y = size // 2, size // 2 player_a_gagner = False ligne = False while game_open: if player_a_gagner: clear() print_char( 1, 1, "Vous avez gagné\n" + "restart: Enter\n" + "exit: CtrlC") key = getKey(debug=True) if key == "\r": demineur() elif ligne: clear() print_char( 1, 1, "Vous avez perdu\n" + "restart: Enter\n" + "exit: CtrlC") for i in range(len(plateau)): print("\n ", end="") for j in range(len(plateau[i])): if plateau[i][j] == 0: char_item = " " elif 1 <= plateau[i][j] <= 8: char_item = plateau[i][j] elif -1 >= plateau[i][j] >= -8: char_item = "\u2588" elif plateau[i][j] == 10: char_item = "\u2588" elif plateau[i][j] == 9: char_item = "\033[31m☭\033[0m" elif plateau[i][j] == 12: char_item = "\033[31m☭\033[0m" else: char_item = "?" print_char(((terminal_size("X") - size) // 2) + i, ((terminal_size("Y") - size) // 2) + j, char_item) key = getKey(debug=True) if key == "\r": demineur() else: print_char( 1, 1, "left: q ou ← \n" + "up: z ou ↑ \n" + "right: d ou → \n" + "down: s ou ↓ \n" + "click: a ou Enter \n" + "flag: e") size_trop_petit = message_page_trop_petite(size + 2, size + 2) if not size_trop_petit: # print(Plateau) player_a_gagner = True for i in range(len(plateau)): print("\n ", end="") for j in range(len(plateau[i])): if plateau[i][j] == 0: char_item = " " elif 1 <= plateau[i][j] <= 8: char_item = plateau[i][j] elif -1 >= plateau[i][j] >= -8: char_item = "\u2588" player_a_gagner = False elif plateau[i][j] == 10: char_item = "\u2588" player_a_gagner = False elif plateau[i][j] == 9: char_item = "\u2588" elif plateau[i][j] == 12: char_item = "\033[31m☭\033[0m" else: char_item = "?" print_char( ((terminal_size("X") - size) // 2) + i, ((terminal_size("Y") - size) // 2) + j, ( lambda elem, char_item_lambda: "⚑" if elem # ⚐⚑ else char_item_lambda)(drapeau_map[i][j], char_item)) print_char(((terminal_size("X") - size) // 2) + x, ((terminal_size("Y") - size) // 2) + y, "X") key = getKey(debug=True) clear() if key == "q" or key == "\x1b[D": x = max(0, x - 1) if key == "d" or key == "\x1b[C": x = min(size - 1, x + 1) if key == "z" or key == "\x1b[A": y = max(0, y - 1) if key == "s" or key == "\x1b[B": y = min(size - 1, y + 1) if key == "a" or key == "\r": if plateau[x][y] == 9: ligne = True if plateau[x][y] < 0: plateau[x][y] = -plateau[x][y] if plateau[x][y] == 10: plateau[x][y] = 0 if key == "e": drapeau_map[x][y] = not drapeau_map[x][y]