Skip to content

Commit

Permalink
move insert_task() to timer.v
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Aug 27, 2023
1 parent 4fb4572 commit 5adcf7c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
48 changes: 48 additions & 0 deletions timer.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import time
import gg
import gx
import os
import strings

const (
time_cfg = gx.TextCfg{
Expand Down Expand Up @@ -192,3 +193,50 @@ fn lock_screen() {
fn (ved &Ved) pomodoro_minutes() int {
return int((ved.now.unix - ved.timer.pom_start) / 60)
}

const (
max_task_len = 40
separator = '|-----------------------------------------------------------------------------|'
)

fn (ved &Ved) insert_task() ! {
if ved.cur_task == '' || ved.task_minutes() == 0 {
return
}
start_time := time.unix(int(ved.task_start_unix))
mut f := os.open_append(tasks_path)!
task_name := ved.cur_task.limit(max_task_len) +
strings.repeat(` `, max_task_len - ved.cur_task.len)
mins := ved.task_minutes().str() + 'm'
mins_pad := strings.repeat(` `, 4 - mins.len)
now := time.now()
if start_time.day == now.day && start_time.month == now.month {
// Single day entry
f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' +
time.now().hhmm() + ' |')!
} else {
// Two day entry (separated by 00:00)
midnight := time.Time{
year: start_time.year
month: start_time.month
day: start_time.day
hour: 23
minute: 59
}
day_start := time.Time{
year: now.year
month: now.month
day: now.day
hour: 0
minute: 0
}

f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' +
midnight.hhmm() + ' |')!
f.writeln(separator)!
f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + day_start.format() + ' | ' +
time.now().hhmm() + ' |')!
}
f.writeln(separator)!
f.close()
}
53 changes: 4 additions & 49 deletions ved.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import gx
import os
import time
import uiold
import strings
import clipboard

const (
Expand Down Expand Up @@ -1707,9 +1706,12 @@ fn (mut ved Ved) open_blog() {
now := time.now()
path := os.join_path(codeblog_path, '${now.year}', '${now.month:02d}', '${now.day:02d}')
parent_dir := os.dir(path)
parent_dir2 := os.dir(parent_dir)
if !os.exists(parent_dir2) {
os.mkdir(parent_dir2) or { panic(err) }
}
if !os.exists(parent_dir) {
os.mkdir(parent_dir) or { panic(err) }
// os.system('mkdir ${parent_dir}')
}
if !os.exists(path) {
os.system('touch ${path}')
Expand Down Expand Up @@ -1923,53 +1925,6 @@ fn (ved &Ved) task_minutes() int {
return int(seconds / 60)
}

const (
max_task_len = 40
separator = '|-----------------------------------------------------------------------------|'
)

fn (ved &Ved) insert_task() ! {
if ved.cur_task == '' || ved.task_minutes() == 0 {
return
}
start_time := time.unix(int(ved.task_start_unix))
mut f := os.open_append(tasks_path)!
task_name := ved.cur_task.limit(max_task_len) +
strings.repeat(` `, max_task_len - ved.cur_task.len)
mins := ved.task_minutes().str() + 'm'
mins_pad := strings.repeat(` `, 4 - mins.len)
now := time.now()
if start_time.day == now.day && start_time.month == now.month {
// Single day entry
f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' +
time.now().hhmm() + ' |')!
} else {
// Two day entry (separated by 00:00)
midnight := time.Time{
year: start_time.year
month: start_time.month
day: start_time.day
hour: 23
minute: 59
}
day_start := time.Time{
year: now.year
month: now.month
day: now.day
hour: 0
minute: 0
}

f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' +
midnight.hhmm() + ' |')!
f.writeln(separator)!
f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + day_start.format() + ' | ' +
time.now().hhmm() + ' |')!
}
f.writeln(separator)!
f.close()
}

fn (mut ved Ved) git_pull() {
os.system('git -C "${ved.workspace}" pull --rebase')
ved.mode = .normal
Expand Down

0 comments on commit 5adcf7c

Please sign in to comment.