Skip to content

Commit b29c723

Browse files
committed
clean up #16
1 parent f88cc2c commit b29c723

File tree

17 files changed

+46
-158
lines changed

17 files changed

+46
-158
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
bin/
22
go-typer
33
run
4+
colorschemes

cmd/fetch.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// NOTE:QUTE FETCHER
2-
// .. maybe cache using a free edge run-time and store in an S3 bucket?
1+
// NOTE: maybe cache using a free edge run-time and store in an S3 bucket?
32
package cmd
43

54
import (
@@ -13,12 +12,12 @@ import (
1312
)
1413

1514
const (
16-
ModeDefault types.Mode = "default" // default mode
17-
ModeWords types.Mode = "words" // word mode
18-
ModeSentences types.Mode = "sentences" // sentence mode
15+
ModeDefault types.Mode = "default"
16+
ModeWords types.Mode = "words"
17+
ModeSentences types.Mode = "sentences"
1918

20-
zenQuotesAPIURL = "https://zenquotes.io/api/random" // ZenQuotes API URL
21-
bibleAPIURL = "https://bible-api.com/john+3:16" // Bible API URL
19+
zenQuotesAPIURL = "https://zenquotes.io/api/random"
20+
bibleAPIURL = "https://bible-api.com/john+3:16"
2221
)
2322

2423
func init() {
@@ -94,7 +93,6 @@ var fetchCmd = &cobra.Command{
9493
},
9594
}
9695

97-
// formatForGameMode formats the text based on the specified game mode.
9896
func formatForGameMode(text string, mode types.Mode) string {
9997
text = utils.FormatText(text)
10098

@@ -108,14 +106,11 @@ func formatForGameMode(text string, mode types.Mode) string {
108106
}
109107
}
110108

111-
// formatForWords formats the text for word mode by splitting it into lines based on spaces.
112-
// Each word is placed on a new line.
113109
func formatForWords(text string) string {
114110
words := strings.Fields(text)
115111
return strings.Join(words, "\n")
116112
}
117113

118-
// formatForSentences formats the text for sentence mode by splitting it into lines based on punctuation.
119114
func formatForSentences(text string) string {
120115
text = strings.ReplaceAll(text, ".", ".\n")
121116
text = strings.ReplaceAll(text, "!", "!\n")

cmd/main.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ import (
1313
)
1414

1515
var (
16-
cursorType string // Cursor type (block or underline)
17-
themeName string // Theme name or path to custom theme file
18-
listThemes bool // List available themes and exit
19-
debugMode bool // Enable debug mode for performance analysis
20-
customText string // Custom text to display in the game
21-
filePath string // Custom text file to read from
16+
cursorType string
17+
themeName string
18+
listThemes bool
19+
debugMode bool
20+
customText string
21+
filePath string
2222
)
2323

2424
var startCmd = &cobra.Command{
2525
Use: "start",
2626
Short: "Start a new game",
2727
Long: "Start a new game of Go Typer. This command will initialize a new game session.",
2828
Run: func(cmd *cobra.Command, args []string) {
29-
// check if the debug mode is enabled and set the log level accordingly
3029
if debugMode {
3130
devlog.DebugEnabled = true
3231
devlog.InitLog()
@@ -35,7 +34,6 @@ var startCmd = &cobra.Command{
3534
cmd.Printf("Debug mode enabled, logging to %s\n", filepath.Join(utils.GetConfigDirPath(), "debug.log"))
3635
}
3736

38-
// check if listThemes is enabled and list available themes
3937
if listThemes {
4038
themes := ui.ListAvailableThemes()
4139
fmt.Println("Available themes:")
@@ -45,7 +43,6 @@ var startCmd = &cobra.Command{
4543
return
4644
}
4745

48-
// check for theme name and load the theme
4946
if themeName != "" {
5047
fmt.Printf("Theme name provided: %s", themeName)
5148
if strings.HasPrefix(themeName, "-") {
@@ -65,41 +62,36 @@ var startCmd = &cobra.Command{
6562
}
6663
}
6764

68-
// check for custom text and set it
6965
if filePath != "" {
7066
data, err := os.ReadFile(filePath)
7167
if err != nil {
72-
cmd.Printf("Warning: Could not read custom text file '%s': %v\n", filePath, err)
68+
cmd.Printf("Could not read custom text file %s: \n", filePath)
69+
os.Exit(0)
70+
7371
} else {
7472
customText = string(data)
7573
}
7674
}
7775

78-
// check for cursor type and set it
7976
if cursorType != "" {
8077
ui.CurrentSettings.CursorType = cursorType
8178
}
8279

83-
// apply settings and start loading
8480
ui.ApplySettings()
8581
ui.StartLoadingWithOptions(ui.CurrentSettings.CursorType, customText)
8682
},
8783
}
8884

8985
func init() {
90-
// Cursor and theme configuration
9186
startCmd.Flags().StringVarP(&cursorType, "cursor", "c", "block", "Cursor type (block or underline)")
9287
startCmd.Flags().StringVarP(&themeName, "theme", "t", "", "Theme name or path to custom theme file (default: default)")
9388
startCmd.Flags().BoolVar(&listThemes, "list-themes", false, "List available themes and exit")
9489

95-
// Debug and logging options
9690
startCmd.Flags().BoolP("verbose", "v", false, "Enable verbose output")
9791
startCmd.Flags().BoolVar(&debugMode, "debug", false, "Enable debug mode for performance analysis")
9892

99-
// Custom text option
10093
startCmd.Flags().StringVarP(&customText, "text", "x", "", "Custom text to display in the game (default: random text)")
10194
startCmd.Flags().StringVarP(&filePath, "file", "f", "", "Custom text file to read from")
10295

103-
// Add command to root
10496
rootCmd.AddCommand(startCmd)
10597
}

colorschemes/dark.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

colorschemes/default.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

colorschemes/monochrome.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

log/debug.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ import (
1111
)
1212

1313
var (
14-
DebugEnabled = false // Enable debug logging
15-
debugFile *os.File // File handle for the debug log
16-
lastFlush time.Time // Last time the log was flushed
14+
DebugEnabled = false
15+
debugFile *os.File
16+
lastFlush time.Time
1717
)
1818

19-
// InitDebugLog initializes the debug log file. It creates a new file in the
20-
// application's config directory and writes initial debug information.
21-
// It also logs the current OS, architecture, number of CPUs, and goroutines.
2219
func InitLog() {
2320
if !DebugEnabled {
2421
return
@@ -44,8 +41,6 @@ func InitLog() {
4441
runtime.GOOS, runtime.GOARCH, runtime.NumCPU(), runtime.NumGoroutine())
4542
}
4643

47-
// DebugLog writes a debug message to the debug log file. It includes a timestamp and the number of goroutines.
48-
// The message is formatted using fmt.Sprintf, and the log is flushed every second.
4944
func Log(format string, args ...interface{}) {
5045
if !DebugEnabled || debugFile == nil {
5146
return
@@ -65,7 +60,6 @@ func Log(format string, args ...interface{}) {
6560
}
6661
}
6762

68-
// CloseDebugLog closes the debug log file if it is open.
6963
func CloseLog() {
7064
if debugFile != nil {
7165
Log("Closing debug log")

types/text_source.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ import (
77
"time"
88
)
99

10-
type Mode string // Mode is a type that represents the different modes of text formatting.
11-
// TextSource is a struct that represents a source of text.
12-
// It contains a URL to fetch the text from and a parser function to process the response.
10+
type Mode string
11+
1312
type TextSource struct {
14-
URL string // URL to fetch text from
15-
Parser func([]byte) (string, error) // Parser function to process the response
13+
URL string
14+
Parser func([]byte) (string, error)
1615
}
1716

18-
// FetchText fetches text from the specified URL and parses it using the provided parser function.
1917
func (s *TextSource) FetchText() (string, error) {
2018
client := &http.Client{
2119
Timeout: 10 * time.Second,

ui/cursor.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
package ui
22

3-
type CursorType int // CursorType represents the type of cursor to be used in the UI.
3+
type CursorType int
44

55
const (
6-
BlockCursor CursorType = iota // Block cursor
7-
UnderlineCursor // Underline cursor
6+
BlockCursor CursorType = iota
7+
UnderlineCursor
88
)
99

10-
var DefaultCursorType CursorType = BlockCursor // Default cursor type
10+
var DefaultCursorType CursorType = BlockCursor
1111

1212
type Cursor struct {
1313
style CursorType
1414
}
1515

16-
// NewCursor creates a new cursor with the specified style.
1716
func NewCursor(style CursorType) *Cursor {
1817
return &Cursor{
1918
style: style,
2019
}
2120
}
2221

23-
// render returns the string representation of the cursor based on its style.
2422
func (c *Cursor) Render(char rune) string {
2523
switch c.style {
2624
case BlockCursor:

ui/global_timer.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88

99
type GlobalTickMsg time.Time
1010

11-
// InitGlobalTick initializes the global tick command with the current refresh interval.
1211
func InitGlobalTick() tea.Cmd {
1312
return GlobalTickCmd(GetRefreshInterval())
1413
}
1514

16-
// HandleGlobalTick processes the global tick message and returns the new tick time,
1715
func HandleGlobalTick(lastTick time.Time, msg GlobalTickMsg) (time.Time, bool, tea.Cmd) {
1816
newTick := time.Time(msg)
1917

@@ -22,15 +20,13 @@ func HandleGlobalTick(lastTick time.Time, msg GlobalTickMsg) (time.Time, bool, t
2220
return newTick, true, cmd
2321
}
2422

25-
// GlobalTickCmd creates a command that ticks at the specified interval.
2623
func GlobalTickCmd(interval time.Duration) tea.Cmd {
2724
return tea.Tick(interval, func(t time.Time) tea.Msg {
2825
return GlobalTickMsg(t)
2926
})
3027
}
3128

32-
// GetRefreshInterval calculates the refresh interval based on the current settings.
33-
// If the refresh rate is set to 0, it defaults to 10 FPS (100ms).
29+
// if set to > 0, defaults to 10 (100ms).
3430
func GetRefreshInterval() time.Duration {
3531
fps := 10
3632
if CurrentSettings.RefreshRate > 0 {

0 commit comments

Comments
 (0)