-
Notifications
You must be signed in to change notification settings - Fork 9
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
otk/ui: introduce some sort of ui #272
base: main
Are you sure you want to change the base?
otk/ui: introduce some sort of ui #272
Conversation
Might need better locking and signal handling around the thread but I didn't encounter any issues so far. We can always move all output into a single object and have it lock. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some quick high-level thoughts:
- would be nice to unify the log/ui concepts, otherwise I see a lot of "ui.print(some-info")";log.info("some-info") in the code (also verbose probably means the same for ui/logs)
- not print if it's not a tty is unusal IME, most tools seem to not do spinners or color but not printing anything is rare (I think?)
- tests :)
Yes, however; see the answer for the second point.
Yes! So in my case the UI is meant to be not-important, only for human eyes. Normal log messages are always shown (interspersed with the UI) and any redirection turns off everything related to the UI. How do you feel?
Of course! (UI's always fun to test). |
A real "spinner" would be nice :-D
|
There are a lot of ways to make the UI prettier, I think the core issue for this right now is my decision to have a UI that is separate from log output and which gets disabled on any redirection. If we decide that that's an OK thing to do then I'll add some tests, we can merge, and we can iterate. |
f9e1017
to
2c517c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with anything a little more verbose "for humans"
although some tests are missing, right? :-) |
I think it is preferable to have a single way to do output, I'm not sure there is a thing as "not important output", it depends on context, when doing a bugreport usually all "log" level output is important but when running in "normal" mode it is not. So having a single way to output seems useful, otherwise we would do things like "ui.print("doing something"); logger.info("doing something") or we would have "ui.print("doing something") and no logger but then when asking for a debug log via "otk compile foo.yaml > output.log" we would miss "doing something" in the output which may (or may not) be an important clue). Also I think building blocks that are orthogonal are important, anytime something is kinda-similar to a different concept we already have I feel uneasy. With this class we have now logging that does output and a new ui that does output. And depending on context (isatty()) some is turned on or off. And depending on verbosity level in logging some is turned on and some is turned off. In many ways this is very similar to logging, we want to control "debug", "warn" etc and a way to increase or decrease verbosity. [edit: sorry, parts where maybe a bit terse/badly phrased, I rewrote the section about "not important output"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there are some commits in this PR that are not related to the title of the PR, is that intentional?
Yes, it needs rebasing again as it was based on top of #277 which just got merged. |
2c517c7
to
4226e62
Compare
4226e62
to
6a59e83
Compare
src/otk/ui.py
Outdated
|
||
|
||
def print(text: str) -> None: # pylint: disable=redefined-builtin | ||
"""Write a line of text to stderr if it's attached to a tty.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an intermediate solution to the valuable input of @mvo5 - should we info/debug-log the text here, to avoid duplication and have those interesting messages also in the logs?
( could as well be the "else" of isatty()
? )
I was asked to re-review this but afaict nothing since my comments in #272 (comment) has changed so they still apply. |
Indeed nothing changed. I'll be taking this PR in the direction you mentioned in the comment. |
c046ec6
to
3c36474
Compare
I've adjusted this PR to have a This allows us to take control of the delegated things, expand functionality, and act as a filter and/or formatter (colors, etc) for output based on the settings of |
We want prettier outputs, let's create an ui submodule to hold primitives for that. This includes the initial implementation of a spinner (which just prints dots for now). Signed-off-by: Simon de Vlieger <[email protected]>
Shows a message with dots appearing after it when an external is running. Signed-off-by: Simon de Vlieger <[email protected]>
The log level for includes can be reduced from INFO to DEBUG to be consistent with out log levels. Signed-off-by: Simon de Vlieger <[email protected]>
Only prints output when stderr is a tty. Signed-off-by: Simon de Vlieger <[email protected]>
Small MOTD to print version and documentation URL. Signed-off-by: Simon de Vlieger <[email protected]>
Use a logger instance as the default output for the UI. The logger instance is still configured by the entrypoint for its levels. The new `Terminal` instance delegates all `Logger` calls but adds a few others such as a `spinner` and `motd`. Signed-off-by: Simon de Vlieger <[email protected]>
Signed-off-by: Simon de Vlieger <[email protected]>
3c36474
to
ea5d39a
Compare
Probably rebased wrongly? Signed-off-by: Simon de Vlieger <[email protected]>
We've spoken about being nice to users before; @schuellerf is working on adding a lot of annotated data to our data structures, I've spent a morning on writing a tiny bit of UI.
The idea is:
Based on #277.