From 93e5c3c67e4516a69eb92eaa64ccacd84e0c3156 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 5 Jul 2023 23:37:16 +0300 Subject: [PATCH] init --- .editorconfig | 10 ++++++ .gitattributes | 7 ++++ .gitignore | 27 +++++++++++++++ src/chalk.v | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.v | 69 ++++++++++++++++++++++++++++++++++++++ src/tasks.v | 15 +++++++++ v.mod | 7 ++++ 7 files changed, 226 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 src/chalk.v create mode 100644 src/main.v create mode 100644 src/tasks.v create mode 100644 v.mod diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7c34908 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.v] +indent_style = tab diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f4011a7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +* text=auto eol=lf +*.bat eol=crlf + +**/*.v linguist-language=V +**/*.vv linguist-language=V +**/*.vsh linguist-language=V +**/v.mod linguist-language=V diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..577ba8e --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# Binaries for programs and plugins +main +t_asker +*.exe +*.exe~ +*.so +*.dylib +*.dll + +# Ignore binary output folders +bin/ + +# Ignore common editor/system specific metadata +.DS_Store +.idea/ +.vscode/ +*.iml + +# ENV +.env + +# vweb and database +*.db +*.js + +# Data +t_asker.json diff --git a/src/chalk.v b/src/chalk.v new file mode 100644 index 0000000..b8336c2 --- /dev/null +++ b/src/chalk.v @@ -0,0 +1,91 @@ +module chalk + +import strconv + +const ( + prefix = '\e[' + suffix = 'm' + foreground_colors = { + 'black': 30 + 'red': 31 + 'green': 32 + 'yellow': 33 + 'blue': 34 + 'magenta': 35 + 'cyan': 36 + 'default': 39 + 'light_gray': 37 + 'dark_gray': 90 + 'light_red': 91 + 'light_green': 92 + 'light_yellow': 93 + 'light_blue': 94 + 'light_magenta': 95 + 'light_cyan': 96 + 'white': 97 + } + background_colors = { + 'black': 40 + 'red': 41 + 'green': 42 + 'yellow': 44 + 'blue': 44 + 'magenta': 45 + 'cyan': 46 + 'default': 49 + 'light_gray': 47 + 'dark_gray': 100 + 'light_red': 101 + 'light_green': 102 + 'light_yellow': 103 + 'light_blue': 104 + 'light_magenta': 105 + 'light_cyan': 106 + 'white': 107 + } + style = { + 'bold': 1 + 'dim': 2 + 'underline': 4 + 'blink': 5 + 'reverse': 7 + 'hidden': 8 + } + fg_rgb = 38 + bg_rgb = 48 + reset = '${prefix}0${suffix}' +) + +pub fn fg(text string, color string) string { + return '${chalk.prefix}${chalk.foreground_colors[color]}${chalk.suffix}${text}${chalk.reset}' +} + +pub fn fg_rgb(text string, r int, g int, b int) string { + return '${chalk.prefix}${chalk.fg_rgb};2;${r};${g};${b}${chalk.suffix}${text}${chalk.reset}' +} + +pub fn fg_hex(text string, hex string) string { + r := strconv.common_parse_int(hex[1..3], 16, 16, true, false) or { 0 } + g := strconv.common_parse_int(hex[3..5], 16, 16, true, false) or { 0 } + b := strconv.common_parse_int(hex[5..7], 16, 16, true, false) or { 0 } + return fg_rgb(text, int(r), int(g), int(b)) +} + +pub fn bg(text string, color string) string { + return '${chalk.prefix}${chalk.background_colors[color]}${chalk.suffix}${text}${chalk.reset}' +} + +pub fn bg_rgb(text string, r int, g int, b int) string { + return '${chalk.prefix}${chalk.bg_rgb};2;${r};${g};${b}${chalk.suffix}${text}${chalk.reset}' +} + +pub fn bg_hex(text string, hex string) string { + r := strconv.common_parse_int(hex[1..3], 16, 16, true, false) or { 0 } + g := strconv.common_parse_int(hex[3..5], 16, 16, true, false) or { 0 } + b := strconv.common_parse_int(hex[5..7], 16, 16, true, false) or { 0 } + return bg_rgb(text, int(r), int(g), int(b)) +} + +pub fn style(text string, color string) string { + return '${chalk.prefix}${chalk.style[color]}${chalk.suffix}${text}${chalk.reset}' +} diff --git a/src/main.v b/src/main.v new file mode 100644 index 0000000..021777e --- /dev/null +++ b/src/main.v @@ -0,0 +1,69 @@ +module main + +import os +import term +import readline { read_line } +import json +import chalk + +const ( + tasker_init = '{"info":{"date_created":0,"date_last_open":3},"tasks":[{"name":"running","last_run":0,"count":0},{"name":"working","last_run":0,"count":0}]}' + tasker_path_home = os.resource_abs_path(os.join_path('~', '.t_asker.json')) + tasker_path_folder = os.resource_abs_path(os.join_path('.', 't_asker.json')) +) + +struct TaskerInfo { + date_created int + date_last_open int +} + +struct TaskerTasks { + name string + last_run int + count int +} + +struct TaskerData { + info TaskerInfo + tasks []TaskerTasks +} + +fn main() { + term.clear() + + mut data := TaskerData{} + mut data_file := os.File{} + + if !os.exists(tasker_path_folder) { + println('t_asker file ' + chalk.fg(chalk.style('not found', 'bold'), 'red') + '!') + println('make new file ' + + chalk.fg(chalk.style(os.norm_path(tasker_path_folder), 'bold'), 'yellow') + '.') + + data = json.decode(TaskerData, tasker_init)! + + data_file = os.open_file(tasker_path_folder, 'w')! + data_file.write_string(json.encode(data))! + } else { + data_string := os.read_file(tasker_path_folder)! + data = json.decode(TaskerData, data_string)! + } + + for true { + term.clear() + println(chalk.fg(chalk.style('TASKS:', 'bold'), 'green')) + for task_index in 0 .. data.tasks.len { + println('[${task_index:2}] ${data.tasks[task_index].name}') + } + println('\nTotal tasks: ' + chalk.fg('${data.count()}', 'yellow') + '.') + + println(chalk.fg(chalk.style('RUNNING', 'blink'), 'red')) + + input := read_line('Select task: ')! + println('Your name is: ${data.tasks[input.int()].name}') + } + + // info := TaskerInfo{0, 3} + // tasks := TaskerTasks{'ololo', 0, 3} + // x := TaskerData{info, tasks} + // println(json.encode(x)) +} diff --git a/src/tasks.v b/src/tasks.v new file mode 100644 index 0000000..f47177c --- /dev/null +++ b/src/tasks.v @@ -0,0 +1,15 @@ +module main + +fn (data &TaskerData) count() int { + return data.tasks.len +} + +fn (data &TaskerData) list_tasks() []TaskerTasks { + mut tasks := []TaskerTasks{} + + for index in 0 .. data.tasks.len { + tasks.insert(0, (data.tasks[index])) + } + + return tasks +} diff --git a/v.mod b/v.mod new file mode 100644 index 0000000..649fa59 --- /dev/null +++ b/v.mod @@ -0,0 +1,7 @@ +Module { + name: 't_asker' + description: '' + version: '0.0.0' + license: 'WTFPL' + dependencies: [] +}