install

installer
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/install

commit 985c1835e5ef824a83fe7cd5f1b582554861af4a
parent 6fd0d2166f6f03cccbba5835da98f6550e1b18fa
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 21 Oct 2016 18:40:03 +0200

Add(prompt): Add small edition support to the input, and choices under it.

Diffstat:
Mscreen.py | 4++--
Mscreens/config/config.py | 62++++++++++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/screen.py b/screen.py @@ -95,6 +95,8 @@ class Screen: def init_colors(self): curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) + curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_WHITE) # Print morphux title and installer version def print_title(self, win): @@ -125,7 +127,6 @@ class Screen: height = 10 win = curses.newwin(height, int(size[1] * 0.75), self.print_title(self.stdscr) + 2, int(size[1] * 0.25 / 2)) win.border() - win.addstr(0, (int(size[1] * 0.75) / 2) - (len(self.curr_screen.config["title"]) / 2), self.curr_screen.config["title"]) self.curr_screen.refresh(win) self.stdscr.leaveok(1) self.stdscr.refresh() @@ -135,7 +136,6 @@ class Screen: key = self.stdscr.getch() self.curr_screen.input(key) win.erase() - win.addstr(0, (int(size[1] * 0.75) / 2) - (len(self.curr_screen.config["title"]) / 2), self.curr_screen.config["title"]) quit = self.curr_screen.refresh(win) if (quit != self.curr_screen.config["id"]): win.erase() diff --git a/screens/config/config.py b/screens/config/config.py @@ -26,8 +26,10 @@ class Config: key = 0 quit = 1 - is_input = 0 - current_string = "" + is_input = 1 + current_string = "morphux" + choices = ["ACCEPT", "CANCEL"] + current_choice = 0 def init(self): self.config = { @@ -39,30 +41,62 @@ class Config: def input(self, key): self.key = key - if (key == curses.KEY_BACKSPACE or key == 127 or key == 0x7f): - self.current_string = self.current_string[:-1] - elif (key > 31 and key < 127): - self.current_string += str(chr(key)) + if (self.is_input and self.current_choice == 0): + if (key == curses.KEY_BACKSPACE or key == 127 or key == 0x7f): + self.current_string = self.current_string[:-1] + elif (key > 31 and key < 127): + self.current_string += str(chr(key)) + if (key == 9): + if (self.current_choice < 2): + curses.curs_set(0) + self.current_choice += 1 + else: + curses.curs_set(1) + self.current_choice = 0; def center(self, win, y, x, string, attr = 0): win.addstr(y, (x / 2) - len(string) / 2, string, attr) - def input_s(self, win, y, x, default): - if self.is_input == 0: - self.current_string = default - self.is_input = 1 - curses.curs_set(1) + def input_s(self, win, y, x): + flag = 0 start_x = int((x * 0.25) / 2) - win.addstr(y, start_x, self.current_string, curses.A_REVERSE) + if (self.current_choice == 0): + flag |= curses.color_pair(4) + win.addstr(y, start_x, self.current_string, curses.A_REVERSE | flag) j = start_x + len(self.current_string) while j < x - start_x: - win.addstr(y, j, " ", curses.A_REVERSE) + win.addstr(y, j, " ", curses.A_REVERSE | flag) j += 1 win.move(y, start_x + len(self.current_string)) + def show_choices(self, win, x, y): + t_len = 0 + i = 0 + for s in self.choices: + t_len += len(s) + x = (x / 2) - ((t_len + 9) / 2) + for s in self.choices: + flag = 0 + win.addstr(y, x, "<") + if i == 0: + flag = curses.color_pair(3) + else: + flag = curses.color_pair(1) + if (i + 1 == self.current_choice): + flag |= curses.A_BOLD | curses.A_REVERSE + win.addstr(y, x + 1, s, flag) + x += 1 + len(s) + win.addstr(y, x, "> ") + x += 6 + i += 1 + def refresh(self, win): + if (self.current_choice == 0): + curses.curs_set(1) size = win.getmaxyx() self.center(win, 2, size[1], "SET YOUR HOSTNAME", curses.A_BOLD) - self.input_s(win, 4, size[1], "morphux") + self.show_choices(win, size[1], 6) + if (self.is_input == 1): + self.input_s(win, 4, size[1]) return self.quit