This commit is contained in:
Alexander Popov 2023-07-05 23:37:16 +03:00
commit 93e5c3c67e
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
7 changed files with 226 additions and 0 deletions

10
.editorconfig Normal file
View File

@ -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

7
.gitattributes vendored Normal file
View File

@ -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

27
.gitignore vendored Normal file
View File

@ -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

91
src/chalk.v Normal file
View File

@ -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}'
}

69
src/main.v Normal file
View File

@ -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))
}

15
src/tasks.v Normal file
View File

@ -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
}

7
v.mod Normal file
View File

@ -0,0 +1,7 @@
Module {
name: 't_asker'
description: ''
version: '0.0.0'
license: 'WTFPL'
dependencies: []
}