Skip to content

Commit

Permalink
changes: makefile restored, long quotes, :retab, error fix in util.go…
Browse files Browse the repository at this point in the history
… while reading files
  • Loading branch information
IAmAnubhavSaini committed Feb 14, 2024
1 parent 99f24d0 commit 8268309
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 35 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DESTDIR :=
#PREFIX := /usr/local
PREFIX := .
PREFIX := /usr/local

.PHONY: all
all:
Expand Down
22 changes: 22 additions & 0 deletions quotes/long
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"text": "It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually strive to do the deeds; who knows great enthusiasms, the great devotions; who spends himself in a worthy cause; who at the best knows in the end the triumph of high achievement, and who at the worst, if he fails, at least fails while daring greatly, so that his place shall never be with those cold and timid souls who neither know victory nor defeat.",
"attribution": "Theodore Roosevelt"
},
{
"text": "I must not fear. Fear is the mind killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain.",
"attribution": "Frank Herbert, Dune"
},
{
"text": "The only thing we have to fear is fear itself nameless, unreasoning, unjustified terror which paralyzes needed efforts to convert retreat into advance. In every dark hour of our national life a leadership of frankness and vigor has met with that understanding and support of the people themselves which is essential to victory.",
"attribution": "Franklin D. Roosevelt"
},
{
"text": "It is easy in the world to live after the world's opinion; it is easy in solitude to live after our own; but the great man is he who in the midst of the crowd keeps with perfect sweetness the independence of solitude.",
"attribution": "Ralph Waldo Emerson, Self-Reliance"
},
{
"text": "The mass of men lead lives of quiet desperation. What is called resignation is confirmed desperation. From the desperate city you go into the desperate country, and have to console yourself with the bravery of minks and muskrats. A stereotyped but unconscious despair is concealed even under what are called the games and amusements of mankind.",
"attribution": "Henry David Thoreau, Walden"
}
]
64 changes: 32 additions & 32 deletions src/db.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
package main

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
)

var FILE_STATE_DB string
var MISTAKE_DB string

func init() {
var ok bool
var data string
var home string
var ok bool
var data string
var home string

if home, ok = os.LookupEnv("HOME"); !ok {
die("Could not resolve home directory.")
}
if home, ok = os.LookupEnv("HOME"); !ok {
die("Could not resolve home directory.")
}

if data, ok = os.LookupEnv("XDG_DATA_HOME"); ok {
data = filepath.Join(data, "/tt")
} else {
data = filepath.Join(home, "/.local/share/tt")
}
if data, ok = os.LookupEnv("XDG_DATA_HOME"); ok {
data = filepath.Join(data, "/tt")
} else {
data = filepath.Join(home, "/.local/share/tt")
}

os.MkdirAll(data, 0700)
os.MkdirAll(data, 0700)

FILE_STATE_DB = filepath.Join(data, ".db")
MISTAKE_DB = filepath.Join(data, ".errors")
FILE_STATE_DB = filepath.Join(data, ".db")
MISTAKE_DB = filepath.Join(data, ".errors")
}

func readValue(path string, o interface{}) error {
b, err := ioutil.ReadFile(path)
b, err := ioutil.ReadFile(path)

if err != nil {
return err
}
if err != nil {
return err
}

return json.Unmarshal(b, o)
return json.Unmarshal(b, o)
}

func writeValue(path string, o interface{}) {
b, err := json.Marshal(o)
if err != nil {
panic(err)
}

err = ioutil.WriteFile(path, b, 0600)
if err != nil {
panic(err)
}
b, err := json.Marshal(o)
if err != nil {
panic(err)
}

err = ioutil.WriteFile(path, b, 0600)
if err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion src/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func readResource(typ, name string) []byte {
return b
}

if b, err := os.ReadFile(name); err != nil {
if b, err := os.ReadFile(filepath.Join(typ, name)); err != nil {
fmt.Println(err)
} else {
return b
Expand Down

0 comments on commit 8268309

Please sign in to comment.