Open Thom1729 opened 6 years ago
Things I'd like:
enum
library.IntEnum
s and IntFlag
s for Sublime's constants.I believe the current OutputPanel abstraction of https://github.com/SublimeText/PackageDev/blob/d22a77646b3b3e9ab06f81ab0b6037ea17ef2380/plugins_/lib/sublime_lib/view/output_panel.py can copied over almost entirely (while keeping in mind that the functions used might need to be adjusted to how this will be structured).
I created #2 for settings.
I've created #3 for the output panel.
More things I'd like to see:
View.add_regions
. Either using the enum
Package Control dependency or vendoring it.on_modified_async
until the user stopped typing for a certain amount of time. I wrote something like this in a gist a few years ago using threads, which is more reliable than sublime.set_timeout_async
, but probably uses more resources.I hope this is the proper place to leave suggestions (and that someone doesn't slap me if this is already in the built-in Sublime Text API) but something that would very well complement the new_window function would be a way to call and use a file picker (for example, to have custom functionality for selecting a file and setting up a window and project based on that).
Edit: please tell me if this is already possible (or absolutely impossible) and wether I should open a new issue instead.
You mean a file picker provided by the os? That's not possible with the current api (excluding direct os calls via ctypes).
I see. Is there instead any python-based implementation of a file picker that we could 'plug-in'? I recently saw a sublime extension opening a colorpicker so that drove my hopes high (but then again, I know next to nothing about UI programming). Where should I look for this?
I don't know if any, but that doesn't mean there isn't. Your unlikely to find it within st plugins, though, and I suspect having more luck in a pypi package.
Your gonna be looking at using ctypes to run OS-level api (or some library's for Linux), I. E. the win32api, cocoa and gtk3, most likely.
An alternative implementation could be using a quick panel or input panel to ask for a plaintext file path but provide a few helpers like completion for file or folder names.
It'd be nice to have a circular OutputPanel -- one that maintains at most N lines and removes old lines when new lines are printed.
It'd be nice to have an idempotent creator function for panels. Like a classmethod called get_or_create
that will return the panel if it already exists, and otherwise create it.
Such a classmethod should have a callable argument that allows the caller to set up the panel when it is first created (and if the panel already exists, the callable is not invoked).
Could you describe a use case for OutputPanel.get_or_create
?
@FichteFoll
We want the diagnostics panel created if it doesn't yet exist, and otherwise just get the existing one.
There should also be a BufferedOutputPanel class. Every call to OutputPanel.print now invokes the command "insert", {"characters": a_tiny_line}
. Running multiple of those in succession creates janky or flickering panels for some users.
My main concern regarding the suggested method was the callback part, but your function does not seem to use that and I was wondering what kind of setup you would need to do.
I would rather indicate in the return value whether the panel existed already to prevent indirection. What do you think of the following?
@classmethod
def find_or_create(cls, window: sublime.Window, name: str, *, **kwargs) -> Tuple[OutputPanel, bool]:
panel = window.find_output_panel(name)
if panel:
return panel, False
else
return cls(window, name, **kwargs), True
Regarding the buffer, when should that be flushed? Periodically? On line breaks? The former would require a separate thread.
It should flush when the underlying stream is closed, or when someone manually calls flush
. Most uses (for me, it seems) are temporarily creating an OutputPanel and doing a bunch of print
s. As a first implementation it should not be too clever.
I suppose it could also be an option like force_writes
and follow_cursor
instead of a separate class. Have buffered=False
by default, but users may override it.
So, I would propose a simple strategy of saving all write
calls to a List[str]
and flushing that in flush()
with a single large "insert", {"characters": "".join(self._buffer)}
. Using this strategy would allow code like this:
with OutputPanel(window, "foo", buffered=True, force_writes=True) as stream:
stream.clear()
for x in ("a", "b", "c"):
stream.print(x)
Instead we still have to write code like this:
render = []
for x in ("a", "b", "c"):
render.append(x)
with OutputPanel(window, "foo", force_writes=True) as stream:
stream.clear()
stream.print("\n".join(render))
I am not sure what the behavior of tell
and others should be when buffering is involved, though.
Imo we should close this issue and split the individual remaining items into separate issues, so they 1) aren't lost and 2) can be talked about in isolation. This issue was mostly made for the initial implementation before the first release where we only talked about ideas and suggestions lightly (like the OP suggests).
@rwols, if you could post your two suggestions as separate issues, that would be much appreciated. I'll go through the list of other ideas with @Thom1729 at a later point in time.
Sounds good to me. I'll make separate issues.
Added a reference to a debounced
decorator I just wrote and shared on the forum instead of the previous very cumbersome thread version.
This issue is for feature suggestions that don't have their own issue (yet). This allows us to brainstorm fearlessly without creating a ton of issues for lightly-considered ideas.
All proposals summarized (constantly updated):
A file-like output panel abstraction.→ #3Predefined→ #9IntEnum
s andIntFlag
s for Sublime's constants.A backported→ #4enum
library.A buffered view abstraction that provides convenience features while avoiding API calls.→ #10A better way to listen for changes to specific settings.→ #2A mapping to convert ST and Python text encoding names (via)→ #23on_modified_async
until the user stopped typing for a certain amount of time. (@FichteFoll wrote a decorator for this on the forum.)