Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite line metadata #109

Merged
merged 1 commit into from Jul 27, 2023
Merged

Overwrite line metadata #109

merged 1 commit into from Jul 27, 2023

Conversation

DrJosh9000
Copy link
Contributor

@DrJosh9000 DrJosh9000 commented Jul 26, 2023

What timestamp should a rewritten line have?

I argue we should replace old line metadata with new metadata. This will make timestamps look more sensible in ESC [1A ESC [K-heavy output.

For example, when faced with updating the existing screen (pseudo-rendered):

<?bk t="0"?>Commencing build...
<?bk t="1"?>Enumerating packages...

with a sequence like ESC [1A ESC [K ESC _bk;t=200 BEL Completed! LF, we currently get

<?bk t="0"?>Commencing build...
<?bk t="1"?>Completed!

which is nonsensical from a timestamp perspective (Completed! actually happened at t=200).

The current approach does have a benefit: assuming the timestamps are non-decreasing, it is somewhat possible to derive the "duration" of a line (assuming each line is printed at the very start of a chunk of processing). In the example above, Commencing build... can be inferred to take Δt = 1; if Completed! has t=200, then Commencing build...'s inferred Δt = 200, when 199 of that was actually spent starting with package enumeration. But to do this effectively requires making that assumption.

I also tweaked the style of setLineMetadata, and implemented an optimisation for clear.

@DrJosh9000 DrJosh9000 requested review from pda and triarius July 26, 2023 05:48
Copy link
Contributor

@triarius triarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

}
p.screen.setLineMetadata(bkNamespace, data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇‍♂️

strings.Join([]string{
`<?bk t="234"?>hello world!`,
`<?bk t="456"?>another line!`,
}, "\n"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a test, so it's moot, but I wonder if the compiler in lines this? At least with the alternative using +, you have this garantee: https://go.dev/ref/spec#Constant_expressions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't 100% sure, so I compiled a test binary and went to crack it open with Ghidra, except I don't have it installed, and it relies on the JDK. Which reminded me that Java (at some point) compiled repeated string concatenations with + into a StringBuilder under the hood.

Anyway, I expect the answer is no. Certainly it doesn't create a single string constant.

}

for i := xStart; i <= xEnd && i < len(line.nodes); i++ {
line.nodes[i] = emptyNode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@DrJosh9000 DrJosh9000 merged commit e5f5775 into main Jul 27, 2023
1 check passed
@DrJosh9000 DrJosh9000 deleted the line-metadata-overwrite branch July 27, 2023 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants