Does cockpit provide internal documentation? #21138
-
I’m curious about how Cockpit implements web terminal shell access, but I found the source code overwhelming. Could someone point me in the right direction? I only could find the user documentation about terminal |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
if I can grasp how cockpit implement the terminal access, I might be able to improve my naive implementation that use telegram bot and write a better code :) |
Beta Was this translation helpful? Give feedback.
-
I can't really tell what your "naive implemenation" does but Cockpit (simplified) serves JavaScript using If you can tell what you want to implement I made be able to give you more information. |
Beta Was this translation helpful? Give feedback.
-
The high-level code is in https://github.com/cockpit-project/cockpit/blob/main/pkg/systemd/terminal.jsx -- it opens a stream channel (i.e. "run a program") to the shell (bash by default), and then hooks this up to a terminal widget which is just a wrapper around XTerm.js. From your brief description it sounds like you don't need to dive down into what the Terminal widget does under the hood, just to use it to display something different? I.e. instead of bash you want to your startService() logic and show it in the terminal? Then you need to use the xterm.js widget directly, as our cockpit-components-terminal.jsx assumes a single process channel. |
Beta Was this translation helpful? Give feedback.
-
After giving a second thought, I think I'm not being clear here. I have a hunch that my previous implementation is not following best practice and I remember that cockpit have some component that related to my implementation, but turns out it's not true. the use case is not same and completely different things, This might be called an X-Y problem. So I ended up create new repository and rewrite my code there. Thanks for the explanation anyway, I really appreciate it! |
Beta Was this translation helpful? Give feedback.
The high-level code is in https://github.com/cockpit-project/cockpit/blob/main/pkg/systemd/terminal.jsx -- it opens a stream channel (i.e. "run a program") to the shell (bash by default), and then hooks this up to a terminal widget which is just a wrapper around XTerm.js.
From your brief description it sounds like you don't need to dive down into what the Terminal widget does under the hood, just to use it to display something different? I.e. instead of bash you want to your startService() logic and show it in the terminal? Then you need to use the xterm.js widget directly, as our cockpit-components-terminal.jsx assumes a single process channel.