Skip to content

Commit 0fee65f

Browse files
committed
fix: more terminal width fixes
1 parent 9c28f90 commit 0fee65f

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

Justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Start hot reloading
2+
dev:
3+
watchexec -- go build -o build/bit -v ./cmd/bit

bin/.just-1.23.0.pkg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hermit

bin/just

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.just-1.23.0.pkg

engine/engine.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,11 @@ func (e *Engine) evaluate() error {
671671
}
672672
var changed string
673673
if target.storedHash != target.realHash {
674-
changed = " (changed)"
674+
changed = "(changed)"
675675
} else {
676-
changed = " (no change)"
676+
changed = "(no change)"
677677
}
678-
logger.Tracef("Hash: %016x -> %016x%s", target.storedHash, target.realHash, changed)
678+
logger.Tracef("%s - %s - %016x -> %016x", changed, target.outputs, target.storedHash, target.realHash)
679679
}
680680
return nil
681681
}

engine/logging/logger.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,21 @@ func NewLogger(config LogConfig) *Logger {
102102

103103
// Scope returns a new logger with the given scope.
104104
func (l *Logger) Scope(scope string) *Logger {
105+
return &Logger{scope: scope, level: l.level, size: l.size}
106+
}
107+
108+
func (l *Logger) getScope() string {
105109
// Margin is 20% of terminal.
106110
size := l.size.Load()
107111
margin := int(size.margin)
112+
scope := l.scope
108113
if len(scope) > margin {
109114
scope = "…" + scope[len(scope)-margin+1:]
110115
} else {
111116
scope += strings.Repeat(" ", margin-len(scope))
112117
}
113118
scope = strings.ReplaceAll(scope, "%", "%%")
114-
return &Logger{scope: scope, level: l.level, size: l.size}
119+
return scope
115120
}
116121

117122
var ansiTable = func() map[LogLevel]string {
@@ -140,8 +145,9 @@ func (l *Logger) getPrefix(level LogLevel) string {
140145
return ""
141146
}
142147
prefix := ansiTable[level]
143-
if l.scope != "" {
144-
prefix = targetColour(l.scope) + l.scope + "\033[0m" + "| " + prefix
148+
scope := l.getScope()
149+
if scope != "" {
150+
prefix = targetColour(scope) + scope + "\033[0m" + "| " + prefix
145151
}
146152
return prefix
147153
}
@@ -203,9 +209,8 @@ func (l *Logger) Exec(dir, command string) error {
203209
defer l.size.Unsubscribe(changes)
204210

205211
// Resize the PTY to exclude the margin.
206-
if w, h, err := term.GetSize(int(os.Stdin.Fd())); err == nil {
207-
_ = pty.Setsize(p, &pty.Winsize{Rows: uint16(h), Cols: uint16(w) - (l.size.Load().margin + 1)})
208-
}
212+
size := l.size.Load()
213+
_ = pty.Setsize(p, &pty.Winsize{Rows: size.height, Cols: size.width - (l.size.Load().margin + 1)})
209214

210215
go func() {
211216
for size := range changes {
@@ -286,7 +291,7 @@ func (l *Logger) writerScanner(wg *sync.WaitGroup, r *io.PipeReader, level LogLe
286291
switch cs.Final {
287292
case 'G': // G is cursor horizontal absolute.
288293
// We have a CHA sequence, so add the margin width.
289-
col := params[0] + 18
294+
col := params[0] + int(l.size.Load().margin) + 2
290295
segment = csi.Text(fmt.Sprintf("\033[%dG", col))
291296

292297
case 'K': // K is erase in line. We want to intercept 1 (clear to start of line) and 2 (clear entire line).
@@ -345,8 +350,8 @@ func (l *Logger) syncTermSize() {
345350
// Watch WINCH for changes.
346351
winch := make(chan os.Signal, 1)
347352
signal.Notify(winch, syscall.SIGWINCH)
348-
defer signal.Stop(winch)
349353
go func() {
354+
defer signal.Stop(winch)
350355
for range winch {
351356
if w, h, err := term.GetSize(int(os.Stdin.Fd())); err == nil {
352357
margin := uint16(max(16, w/5))

0 commit comments

Comments
 (0)