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

Handle limited capacity history and the order, truncate history file as needed #8

Merged
merged 6 commits into from
Aug 9, 2024

Conversation

ldemailly
Copy link
Member

@ldemailly ldemailly commented Aug 8, 2024

Copy link

codecov bot commented Aug 9, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@ldemailly ldemailly changed the title Handle limited capacity history, leaving 1 slot for pending and keeping newest when loading/saving Handle limited capacity history and the order, truncate history file as needed Aug 9, 2024
@ldemailly ldemailly merged commit 5ff44b9 into main Aug 9, 2024
4 of 6 checks passed
@ldemailly ldemailly deleted the history_with_nl_and_dedup branch August 9, 2024 18:51
@@ -3,7 +3,7 @@ all: lint test demo
GO_BUILD_TAGS:=no_net,no_json,no_pprof

demo:
go run -tags $(GO_BUILD_TAGS) ./example/ -loglevel debug
go run -tags $(GO_BUILD_TAGS) ./example/ -loglevel debug -only-valid
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
go run -tags $(GO_BUILD_TAGS) ./example/ -loglevel debug -only-valid
go run -tags $(GO_BUILD_TAGS) ./example/ -loglevel debug -only-valid

I'm a crazy person 🤪

BTW, do you know unmake?

Makefile linter
https://github.com/mcandre/unmake

Copy link
Member Author

Choose a reason for hiding this comment

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

I can tell :) fixing it, installed unmake but will ignore

warning: Makefile: MAKEFILE_PRECEDENCE: lowercase Makefile to makefile for launch speed
warning: Makefile:1: STRICT_POSIX: lead makefiles with the ".POSIX:" compliance marker, or else rename include files like *.include.mk
warning: Makefile:8: COMMAND_COMMENT: comment embedded inside commands will forward to the shell interpreter
warning: Makefile:14: COMMAND_COMMENT: comment embedded inside commands will forward to the shell interpreter

and

error: Makefile:3:15 found "=", expected: LF, comment, inline command, macro expansion, target, wait prerequisite marker

(it doesn't know about := ? uh?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Dunno about unmake, but it helped me to spot some issues

func AddOrReplaceHistory(t *terminal.Terminal, replace bool, l string) {
// if in default auto mode, we don't manage history
// we also don't add empty commands. (at start of program)
if t.AutoHistory() || l == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also add something to do not log command starting with space, as it's a common pattern to ignore thing in history

Copy link
Member Author

Choose a reason for hiding this comment

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

never heard of leading space preventing history before:

$    echo "this had space"
$  history | tail
 568     echo "this had space"
 569  history | tail

also I do want spaces in history for grol indentation

Copy link
Contributor

Choose a reason for hiding this comment

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

example/main.go Show resolved Hide resolved
terminal.go Show resolved Hide resolved
terminal.go Show resolved Hide resolved
Comment on lines +122 to +128
t.autoHistory = enabled
t.term.AutoHistory(enabled)
}

// AutoHistory returns the current auto history setting.
func (t *Terminal) AutoHistory() bool {
return t.autoHistory
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you forked golang/term in fortio, but I find strange that you now have two flags about autoHistory, one in fortio/term and one in fortio/terminal

BTW, maybe renaming fortio/term to something like fortio/golang-term-fork would make it easier to understand why fortio has now two "term" packages

Copy link
Member Author

Choose a reason for hiding this comment

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

as mentioned, this one (terminal) is standalone and fully encapsulate what happens to be an implementation detail

this being said, others that for instance don't want fortio cli/logger/etc... might use the lower level term directly if they also don't want to wait for PRs to merge upstream (which may or may not ever happen)

terminal.go Show resolved Hide resolved
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.

dedup in history: don't add the same entry twice quote the commands in history (for when \n will work)
2 participants