Skip to content

Commit

Permalink
Start testing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
robinovitch61 committed Nov 13, 2022
1 parent 42060a2 commit eb33e87
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 2 additions & 3 deletions internal/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package dev
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/robinovitch61/wander/internal/tui/constants"
"log"
"os"
)

var debugSet = os.Getenv("WANDER_DEBUG")

// dev
func Debug(msg string) {
if debugSet != "" {
if constants.DebugSet {
f, err := tea.LogToFile("wander.log", "")
if err != nil {
fmt.Println("fatal:", err)
Expand Down
6 changes: 6 additions & 0 deletions internal/tui/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package constants
import (
"github.com/charmbracelet/lipgloss"
"github.com/robinovitch61/wander/internal/tui/style"
"os"
"strings"
"time"
)

var (
DebugSet = os.Getenv("WANDER_DEBUG") != ""
TestingModeSet = os.Getenv("WANDER_TEST_MODE") != ""
)

const NoVersionString = "built from source"

var LogoString = strings.Join([]string{
Expand Down
8 changes: 7 additions & 1 deletion internal/tui/formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/robinovitch61/wander/internal/tui/constants"
constants "github.com/robinovitch61/wander/internal/tui/constants"
"math"
"regexp"
"strings"
Expand Down Expand Up @@ -95,6 +95,9 @@ func ShortAllocID(allocID string) string {
}

func FormatTime(t time.Time) string {
if constants.TestingModeSet {
return "2006-01-02T15:04:05"
}
if t.IsZero() {
return "-"
}
Expand All @@ -119,6 +122,9 @@ func pluralize(s string, q float64) string {
}

func FormatTimeNsSinceNow(t int64) string {
if constants.TestingModeSet {
return "0"
}
tm := time.Unix(0, t).UTC()
since := time.Now().Sub(tm)
if secs := since.Seconds(); secs > 0 && secs < 60 {
Expand Down

0 comments on commit eb33e87

Please sign in to comment.