Skip to content

Commit a17e2de

Browse files
committed
fix: dont useless call terminalWidth()
strace shows a lot of ioctl(0, TIOCGWINSZ, ... ) unnecessarily calls terminalWidth to refresh
1 parent 4f548e1 commit a17e2de

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/ui/scroll.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# SPDX-License-Identifier: MPL-2.0
22
# scroll.nim
33

4-
import strutils, terminal, illwill
4+
import strutils, terminal, illwill, ../utils/utils
55

66
proc clearLineForScroll(start: int, len: int, indentLevel: int = 0) =
77
## Clears a specific portion of the line for scrolling.
88

99
# Ensure start is within bounds
10-
if start >= 0 and start < terminalWidth():
10+
if start >= 0 and start < termWidth:
1111
setCursorPos(start, 2)
1212

1313
# Ensure we don't clear beyond the terminal width
14-
let clearLen = min(len, terminalWidth() - start)
14+
let clearLen = min(len, termWidth - start)
1515

1616
if clearLen > 0:
1717
stdout.write(" ".repeat(clearLen))
@@ -47,7 +47,7 @@ proc scrollTextOnce*(
4747
let clearStart = xStart
4848

4949
# Ensure visibleChunk length does not exceed terminal width
50-
let clearLen = min(visibleChunk.len, terminalWidth() - clearStart)
50+
let clearLen = min(visibleChunk.len, termWidth - clearStart)
5151

5252
# Clear only the portion where the text will be displayed
5353
clearLineForScroll(clearStart, clearLen, indentLevel + 1)

src/utils/utils.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ proc validateLengthStationName*(result: seq[string], filePath: string, maxLength
4343
warnCount += 1
4444

4545
proc checkIfTooLongMagic*(): int =
46-
terminalWidth() - " Now Playing: ".len - 6
46+
termWidth - " Now Playing: ".len - 6
4747

4848
proc checkIfTooLongForUI*(str: string): bool =
49-
#str.len > int(terminalWidth().toFloat() / 1.65)
5049
str.len > checkIfTooLongMagic()
5150

5251
proc truncateMe*(str: string): string =

0 commit comments

Comments
 (0)