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

How to access console output from Far Plugin? #2387

Open
faerot opened this issue Sep 17, 2024 · 17 comments
Open

How to access console output from Far Plugin? #2387

faerot opened this issue Sep 17, 2024 · 17 comments

Comments

@faerot
Copy link
Contributor

faerot commented Sep 17, 2024

Is it possible? How?

@akruphi
Copy link
Contributor

akruphi commented Sep 17, 2024

Far2 API documentation (from classic windows version) you can see in https://api.farmanager.com/ru/index.html (in Russian).
far2l API changes you can see in https://github.com/elfmz/far2l/blob/master/HACKING.md

May be SaveScreen and Text from https://api.farmanager.com/ru/miscapi/index.html help you.

@shmuz
Copy link
Contributor

shmuz commented Sep 17, 2024

@akruphi Your 1-st link is for Far3 API not Far2
@faerot I can send you Far2 Encyclopedia (contains API) in CHM format

@akruphi
Copy link
Contributor

akruphi commented Sep 17, 2024

Far2 Encyclopedia CHM can be downloading within far2.x86.msi/far2.x64.msi from https://farmanager.com/history.php (two last links)

@faerot
Copy link
Contributor Author

faerot commented Sep 17, 2024

Sorry, probably I was not clear enough. I am not talking about current screen of Far, I am talking about terminal output of the last command. The one that is covered by panels, SaveScreen will not help me here. Didn't find anything in the encyclopedia.

@elfmz
Copy link
Owner

elfmz commented Sep 17, 2024

Its not exposed to API anyhow for now, but can consider it. So please tell what you want to achieve to understand how its better to implement

@elfmz
Copy link
Owner

elfmz commented Sep 17, 2024

And may be it can be useful for you - its how console history is accessible inside far2l itself: https://github.com/elfmz/far2l/blob/master/far2l/src/vt/vtlog.h

@faerot
Copy link
Contributor Author

faerot commented Sep 17, 2024

Its not exposed to API anyhow for now, but can consider it. So please tell what you want to achieve to understand how its better to implement

I would like to make a plugin which will scan the traceback from the console and will automatically open editor on the appropriate file, line, and column. That would be very helpful because this happens all the time when I run some script, something crashes, I scan the file name, go to the file, open it, Alt+F8, input line, etc.

@faerot
Copy link
Contributor Author

faerot commented Sep 17, 2024

I assume

std::string GetAsFile(HANDLE con_hnd, bool colored, bool append_screen_lines = true);

Is what would be helpful if exposed to plugin.

@m32
Copy link
Contributor

m32 commented Sep 20, 2024

A much better solution is to make WinPort.h functions available to Python, just like C/C++ plugins have.

switch to user screen:
self.parent.info.Control(self.hplugin, self.ffic.FCTL_GETUSERSCREEN, 0, 0)

hr = winport.GetConsoleScreenBufferInfo(...)
hr = winport.ReadConsoleOutput(...)

switch back:
self.parent.info.Control(self.hplugin, self.ffic.FCTL_SETUSERSCREEN, 0, 0)

@faerot
Copy link
Contributor Author

faerot commented Sep 21, 2024

A much better solution is to make WinPort.h functions available to Python, just like C/C++ plugins have.

switch to user screen: self.parent.info.Control(self.hplugin, self.ffic.FCTL_GETUSERSCREEN, 0, 0)

hr = winport.GetConsoleScreenBufferInfo(...) hr = winport.ReadConsoleOutput(...)

switch back: self.parent.info.Control(self.hplugin, self.ffic.FCTL_SETUSERSCREEN, 0, 0)

Will it allow to get full output - even parts that are not currently visible?

@m32
Copy link
Contributor

m32 commented Sep 21, 2024

unfortunately not :(, the rest is hidden in the _memories buffer

@m32
Copy link
Contributor

m32 commented Sep 21, 2024

Wouldn't it be easier to use a decorator to catch errors?

def handle_exception(exc_type, exc_value, exc_traceback):
...

def handle_error(func):
    def __inner(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception:
            exc_type, exc_value, exc_tb = sys.exc_info()
            handle_exception(exc_type, exc_value, exc_tb)
    return __inner

@handle_error
def Open...

@faerot
Copy link
Contributor Author

faerot commented Sep 21, 2024

unfortunately not :(, the rest is hidden in the _memories buffer

then exposing GetAsFile is better

@faerot
Copy link
Contributor Author

faerot commented Sep 21, 2024

Wouldn't it be easier to use a decorator to catch errors?

Not sure I understood you. Are you questioning the need/usefulness of the plugin which will scan traceback from console?

@m32
Copy link
Contributor

m32 commented Sep 21, 2024

GetAsFile is more complete and explicit, as I find getting the traceback from a variable rather than licking it from the screen

@faerot
Copy link
Contributor Author

faerot commented Sep 21, 2024

Getting traceback in code as you develop and scanning the crash that already happened and dumped in output are two completely different cases. Scanning traceback from output and opening in Far editor is a universal solution which works not only for your code, but for crashes in other people's code. Also it can work not just for python, but for any language that prints parse-able traceback, Node.js, etc. The parser would work not only just from output, it would also work from far viewer so you can conveniently jump from tracebacks in logs too, but scanning output stream is essential for such plugin to be useful for me.

@elfmz
Copy link
Owner

elfmz commented Oct 20, 2024

please see #2454 - if its ok, or may be ned to add something?

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

No branches or pull requests

5 participants