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

Toggle yazi and terminal #1951

Open
2 of 3 tasks
Fildo7525 opened this issue Nov 25, 2024 · 10 comments
Open
2 of 3 tasks

Toggle yazi and terminal #1951

Fildo7525 opened this issue Nov 25, 2024 · 10 comments
Labels
feature New feature request

Comments

@Fildo7525
Copy link

yazi --debug output

Yazi
    Version: 0.3.3 (VERGEN_IDEMPOTENT_OUTPUT 2024-11-25)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.3 (VERGEN_IDEMPOTENT_OUTPUT 2024-11-25)

Emulator
    Emulator.via_env: ("screen-256color", "")
    Emulator.via_csi: Ok(Unknown([]))
    Emulator.detect : Unknown([])

Adapter
    Adapter.matches: X11

Desktop
    XDG_SESSION_TYPE           : Some("x11")
    WAYLAND_DISPLAY            : None
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL              : Some("/bin/bash")
    EDITOR             : Some("/usr/bin/nvim")
    VISUAL             : None
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None

Text Opener
    default: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block  : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : tmux 3.2a
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file             : 5.41
    ueberzugpp       : No such file or directory (os error 2)
    ffmpegthumbnailer: No such file or directory (os error 2)
    magick           : No such file or directory (os error 2)
    fzf              : 0.29
    fd               : No such file or directory (os error 2)
    rg               : 13.0.0
    chafa            : No such file or directory (os error 2)
    zoxide           : No such file or directory (os error 2)
    7z               : No such file or directory (os error 2)
    7zz              : No such file or directory (os error 2)
    jq               : 1.6


--------------------------------------------------
When reporting a bug, please also upload the `yazi.log` log file - only upload the most recent content by time.
You can find it in the "/home/fildo7525/.local/state/yazi" directory.

Please describe the problem you're trying to solve

Let's say you want to be in one tab and run the program you wrote. That will block Yazi until the program finishes the execution. If I want to see the output, there is no way to do so. I could also change to a different directory in the second tab to do other stuff there while the program runs in the first tab.

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

I would like to have something similar to what is in Midnight Commander. After invoking a keymap a terminal and its output will be displayed. Running a code in the terminal will not block yazi.

Additional context

No response

Validations

  • I have searched the existing issues/discussions
  • The latest nightly build doesn't already have this feature
@Fildo7525 Fildo7525 added the feature New feature request label Nov 25, 2024
@sxyazi
Copy link
Owner

sxyazi commented Nov 26, 2024

I haven't used Midnight Commander myself. Could you explain in more detail what this feature is like? It would be really helpful if there's a video demo.

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Nov 26, 2024
@Fildo7525
Copy link
Author

This is what I meant:

mc_terminal_toggle.mp4

You can enter commands and switch to the terminal nothing is blocked. If you switch to the terminal you can run other commands.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Nov 26, 2024
@sxyazi
Copy link
Owner

sxyazi commented Nov 27, 2024

This is really interesting! I never thought about using shells like this.

But integrating it into Yazi might not be trivial, I have a few questions:

  • I'm not quite sure how mc does this. Does it have a built-in terminal emulator, like how nvim's :terminal works?
  • It switches back and forth between mc and the terminal using C-o right? What happens if the program running in the terminal also needs the C-o shortcut?
  • Can it be closed or hidden, or does it always need to occupy a part of the bottom of the screen?

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Nov 27, 2024
@Fildo7525
Copy link
Author

  • There is an integrated terminal. When the MC is closed the running processes are aborted unless they are detached. The thing I do not like about it is that the history from the terminal is pasted into the .history file at $HOME.
  • Yes, the keymap is C-o. And the second question I do not know, but I am sure that the keymap can be adjusted.
  • That I do not know also. But that is just visual thing. In yazi there is the ':' and ':' keymap so I guess that shouldn't be an issue.

The mc is also keyboard based and if you start typing a command you cannot use vim-based movement in the terminal. The movement works only if you do not have anything written in your terminal. To invoke any other movement you need to press one of the Fn keys

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Nov 27, 2024
@sxyazi
Copy link
Owner

sxyazi commented Nov 27, 2024

Thanks for the explanation, but I'm still confused about the following questions:

  • When you mention "integrated terminal", what exactly does it refer to? Is there any documentation on how it works?
  • When returning from mc to the terminal, how does mc continue to listen for C-o and wait for the user to resume?
  • How does mc display the user's terminal at the bottom? Does mc simulate it itself, or does it use some terminal feature?
  • Is mc's shell feature implemented through any Unix-specific APIs? Can it work on Windows?
  • Yazi's : is a one-time shell command and doesn't keep a session. If we want to integrate it with mc's shell feature, what do you have in mind?

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Nov 27, 2024
@Fildo7525
Copy link
Author

For most of the questions you have I do not know the answer I did not study the repository for mc. https://github.com/MidnightCommander/mc. This is their repo. When I wind time for it I will try to look at it. From what I saw it is written in C. I do not use windows so I cannot tell you if it works there too

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Nov 27, 2024
@Fildo7525
Copy link
Author

Regarding the commands run

I went throught the code. The bottom function they use is

/* --------------------------------------------------------------------------------------------- */
/**
 * Wrapper for execvp() system call.
 */

int
my_execvp (const char *file, char *const argv[])
{
    return execvp (file, argv);
}

It is located in file mc/lib/utillinux.c The file is the command

It is called via fork in the same file in function my_systemv (const char *command, char *const argv[])

    case FORK_CHILD:
        {
            my_signal (SIGINT, SIG_DFL);
            my_signal (SIGQUIT, SIG_DFL);
            my_signal (SIGTSTP, SIG_DFL);
            my_signal (SIGCHLD, SIG_DFL);

            my_execvp (command, argv);
            my_exit (127);      /* Exec error */
        }
        MC_FALLTHROUGH;
        /* no break here, or unreachable-code warning by no returning my_exit() */

Subshell

The main code is in

int
invoke_subshell (const char *command, int how, vfs_path_t **new_dir_vpath)

They split the flow into 2 sections when the user hits C-o and when the user enters the command in the bottom line.

@Fildo7525
Copy link
Author

I would be up to helping you to implement the stuff, but I do not know rust.

@sxyazi
Copy link
Owner

sxyazi commented Nov 27, 2024

I have some difficulty reading the MC code because I don't know C, especially for such a large project.

Could you write a minimal demo for me in a language you're familiar with, like C or Python, so that I can have ChatGPT explain it to me?

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Nov 28, 2024
@Fildo7525
Copy link
Author

I do not have much time now. If I have time, I will do it during the weekend. It will probably be easiest in C.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants