import "../common"
+COLOR_FIRST :: 16
+COLOR_SECOND :: 17
+COLOR_THIRD :: 18
+
Config :: struct {
selected_profile: Maybe(string),
}
box_message: Maybe(^nc.Window),
info_bar: ^nc.Window,
+ input_window: ^nc.Window,
config: Config,
profile_password: Maybe(string),
nc.keypad(screen, true)
nc.curs_set(0)
+ nc.use_default_colors()
+ nc.start_color()
+
+ nc.init_color(COLOR_FIRST, 800, 800, 800)
+ nc.init_color(COLOR_SECOND, 500, 500, 500)
+ nc.init_color(COLOR_THIRD, 100, 100, 100)
+
+ nc.init_pair(1, nc.COLOR_WHITE, COLOR_THIRD)
+
screen_height, screen_width := nc.getmaxyx(screen)
- info_bar := nc.newwin(0, 0, 3, screen_width)
+ info_bar := nc.newwin(1, screen_width, screen_height - 2, 0)
+ input_window := nc.newwin(1, screen_width, screen_height - 1, 0)
- nc.box(info_bar, 0, 0)
- nc.wrefresh(info_bar)
+ nc.refresh()
home_path := os.get_env("HOME")
storage_path := fpath.join({ home_path, "mesange" })
}
}
- return {
+ app := App{
screen = screen,
storage_path = storage_path,
+
+ info_bar = info_bar,
+ input_window = input_window,
}
+
+ app_set_state(&app, .Load_Config)
+
+ return app
}
app_deinit :: proc(app: App) {
config_deinit(app.config)
+ nc.delwin(app.input_window)
nc.delwin(app.info_bar)
if box_message, ok := app.box_message.?; ok {
}
app_set_state :: proc(app: ^App, state: State) {
- app_clear_box_message(app)
-
nc.clear()
nc.refresh()
+ app_clear_box_message(app)
+ app_clear_info_bar(app^)
+
app.state = state
}
app_set_info_bar :: proc(app: ^App, content: string) {
-
+ c_content := strings.clone_to_cstring(content, context.temp_allocator)
+
+ color := nc.COLOR_PAIR(1)
+
+ nc.wattron(app.info_bar, color)
+ nc.wprintw(app.info_bar, c_content)
+ nc.wattroff(app.info_bar, color)
}
app_set_box_message :: proc(app: ^App, lines: []string) {
}
height := i32(len(lines)) + 2
- width := i32(max_line_len) + 2
+ width := i32(max_line_len) + 4
box_message := nc.newwin(
height, width,
- (screen_height - height) / 2,
+ (screen_height - height) / 2 - 2,
(screen_width - width) / 2,
)
+ nc.refresh()
+
+ nc.wattron(box_message, COLOR_FIRST)
+
for line, i in lines {
c_line := strings.clone_to_cstring(line, context.temp_allocator)
- nc.mvwprintw(box_message, i32(i + 1), 1, c_line)
+ nc.mvwprintw(box_message, i32(i + 1), 2, c_line)
}
nc.box(box_message, 0, 0)
+ nc.wattroff(box_message, COLOR_FIRST)
+
nc.wrefresh(box_message)
app.box_message = box_message
}
app_clear_info_bar :: proc(app: App) {
+ height, width := nc.getmaxyx(app.info_bar)
+
+ color := nc.COLOR_PAIR(1)
+
+ nc.wclear(app.info_bar)
+ nc.wattron(app.info_bar, color)
+
+ for _ in 0..<width {
+ nc.waddch(app.info_bar, ' ')
+ }
+
+ nc.wattroff(app.info_bar, color)
+ nc.wrefresh(app.info_bar)
}
app_clear_box_message :: proc(app: ^App) {
screen_height, screen_width := nc.getmaxyx(app.screen)
nc.curs_set(1)
- nc.mvgetnstr(screen_height - 1, 0, raw_data(buffer[:]), len(buffer))
+ nc.mvwgetnstr(app.input_window, 0, 0, raw_data(buffer[:]), len(buffer))
nc.curs_set(0)
+ nc.wclear(app.input_window)
+
return strings.clone_from_cstring(cstring(raw_data(&buffer)))
}