ii8 / havoc

minimal terminal emulator for wayland
Other
106 stars 18 forks source link

SailfishOS port #18

Closed Kabouik closed 4 years ago

Kabouik commented 4 years ago

I was trying to package havoc for Sailfish OS, and was surprised I could actually build it on SFOS 3.3.0.16 with this (for reference to remember which packages were necessary)

git clone https://github.com/ii8/havoc.git
cd havoc
devel-su
zypper install wayland-protocols-devel
zypper install libxkbcommon-devel
zypper install wayland-devel
exit
make CFLAGS="-O2 -DNDEBUG"
devel-su make install

I now have the proper binary in /usr/local/bin, unfortunately I get this when trying to execute it:

[nemo@Sailfish havoc]$ havoc
could not open font file: No such file or directory
using fallback font
your compositor does not support xdg_wm_base, make sure you have the latest version

I am not a coder at all, and am not familiar with how compositors work (or even what they are exactly), but SailfishOS does use Wayland. This is the version we have: 1.17.0+git1-1.4.1.jolla.

Is there any hope, or does havoc depend on a more recent version? Another SFOS user told me this:

<Nico[m]> Sailfish doesn't have a concept of maximize, minimize, etc, so wm_base doesn't make much sense. You can probably rip that out and it may work fine

Would that be doable? What should I look for in the sources?

Alternatively, we have some partial Flatpak support on SFOS (just in case you would be planning on a Flatpak release in the future).

ii8 commented 4 years ago

Ok, I believe it should work now.

ii8 commented 4 years ago

I also added an error check for the key repeat timer, so if you look at the logs, maybe it says something useful.

Kabouik commented 4 years ago

Huh, that's interesting. None of the native terminals set $TERM when I launch them. Or as far as I understand they don't override my ~/.bash_profile. I kind of suspected setting $TERM there was a bad idea, but in our case it really does solve refreshing/redraw issues in ncurses apps, even in nano. I didn't find any other solution yet unfortunately.

Resizing confirmed to work without changing $TERM in the latest commit, nice!

Regarding repeat keys, is that stderr that I should check? I still see those unknown DEC Reset-Mode xxxx but nothing printing when I just hold a key in havoc.

ii8 commented 4 years ago

What's probably happening is that when you run havoc, ~/.bash_profile is not even executed at all, bash_profile only runs for login shells. The terminals can't override bash_profile, because that runs afterwards. The order is like this:

Run havoc -> havoc sets TERM -> havoc executes bash -> bash executes ~/.bashrc but not ~/.bash_profile -> bash prompt appears

or:

Run fingerterm -> fingerterm sets TERM -> fingerterm executes bash as login shell -> bash executes ~/.bash_profile and ~/.bashrc -> bash prompt appears

I don't know why it would execute bash as a login shell, normally you don't do that unless it's actually on login, at least on desktop.

And yeah, stderr logs, if there's nothing new there I guess we'll have to check with gdb at some point to find out what's wrong.

Kabouik commented 4 years ago

Alright, I removed the manually set variable in my ~/.bash_profile because it is not an ideal workaround for my issues in other terminals anyway, too many risks to break other things. However, what it solves outweighs what it breaks, so instead I set some aliases to temporarily alter TERM for commands that I know don't display correctly with the default TERM value.

I can confirm the other terminals now use their own TERM value, just like havoc was doing already.

I cannot debug in gdb right now (I just tried gdb havoc then run, but nothing more than what stderr already shows), but I am happy to do it later tonight or tomorrow. I can try alone to save your time, but I remember you gave me detailed instructions I would never have come up with by myself the last time.

ii8 commented 4 years ago

I have a few questions:

(1) Which way should havoc rotate for landscape?

(2) Is that always the same? Or might it be different for different phones?

(3) In an ideal scenario would it be good to have both portrait and landscape? Or is portrait completely pointless once you have landscape?

Kabouik commented 4 years ago
  1. The hardware keyboard is always where the yellow arrow shows, so 90° CW rotation would be ideal for havoc.

📲

  1. As far as I know, yes. There are few keyboard slider phones and I think they are always orientated that way. There might be exceptions, but unlikely to run Sailfish OS or other related OSes. PostmarketOS and Leste might enable new devices, but that's not ready for use yet and those should be able to install master havoc.

  2. Portrait is not completely pointless, but wouldn't be a huge advantage unless havoc can show the virtual keyboard in the future. This would make it useable on all devices, but until then (and if that happens), portrait would only be useful to those who specifically need to display CLI monitoring tools in portrait. And those would still be either people with a slider-phone, so they would mostly use landscape anyway, or people using scripts or third party apps to issue commands into havoc, and they could still do that in landscape.

  3. Something we didn't think about so far: text selection and scrolling. We can scroll with tmux but making it mandatory is not ideal. Native terminals support touch, but I don't know how it's implemented. Konsole (flatpak) supports touch and even emulates mouse input on taps in mouse-enabled tools (like cmus, nnn, etc.), but that might be because it's shipped with more recent protocols that support this (?).

ii8 commented 4 years ago

There is an interface for touch events; https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_touch nvm, it's not available in sailfishOS, there's this: https://github.com/qt/qtwayland/blob/dev/src/extensions/touch-extension.xml but it doesn't say how it works or how to use it. I wouldn't know what the gestures should be though. Is it just 1 finger to select, 2 fingers to scroll?

I've never done mouse input for cli applications even for the desktop havoc, I find it annoying most of the time when I'm just trying to select and copy-paste. But it's not too hard I think.

Kabouik commented 4 years ago

Currently native terminals have a GUI button to toggle gestures between select and scroll modes (plus one mode to show/hide the keyboard but that's probably because they don't use the stock SFOS keyboard, which I think already has this gesture to hide builtin), and then they use just one finger.

I'm not sure if they do that because of a software limitation, or because devs didn't want multi-touch gestures at the time. Again, there are all more or less forks of the same, so they could all use that because they inherited it, not necessarily because there is no other way.

I think the toggle is a pain, actually, so if that would be doable, I would probably prefer one finger for one action, and two (or Shift+finger) for the other. That would certainly deserve some more thinking though.

ii8 commented 4 years ago

Ok, I did the landscape rendering, turns out it's not actually very hard at all.

Kabouik commented 4 years ago

Amazing! Glad it was simpler than expected.

I played with havoc a little more now that I can really interact with it easily, and there's no doubt this is going to be a significant progress compared to the native terminals. Perhaps mostly for those with a hardware keyboard at first, but still i'm sure others could come up with some scripts, desktop files, or use this to benefit from the improved havoc output.

ingenieroariel commented 4 years ago

Thanks for your work on this! Really hoping to have a similar experience with NixOS Mobile with Sway when my PinePhone arrives.

Loved witnessing the back and forth over the past few days.

Gracias.

On Mon, 1 Jun 2020 at 8:13 PM Kabouik notifications@github.com wrote:

Amazing! Glad it was simpler than expected.

I played with havoc a little more now that I can really interact with it easily, and there's no doubt this is going to be a significant progress compared to the native terminals. Perhaps mostly for those with a hardware keyboard at first, but still i'm sure others could come up with some scripts, desktop files, or use this https://openrepos.net/content/coanteen/qcommand to benefit from the improved havoc output.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ii8/havoc/issues/18#issuecomment-637209488, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAANNVYECB2UOTX7MIQDDLLRURG3ZANCNFSM4NLNDWUA .

Kabouik commented 4 years ago

Short summary:

I was playing with npm and noticed a few wrong characters in some CLI charts or animations. I tested printf '\xe2\x99\xa5' in havoc, and it turns out it cannot display it, as opposed to Fingerterm/Toeterm. My locale is set as en_GB.UTF-8 in environment. Using tmux didn't help.

What surprises me is I'm pretty sure I got accents and other UTF-8 characters working at some point in the past few days, because that was something I was checking when using cmus to test havoc builds. Obviously this must be something on my phone because I don't think you changed anything in that regard, but I fail to see what that could be and why other terminals don't pick it the same way.

ii8 commented 4 years ago

I can display that character fine on desktop. It's likely related to the specific font you are using.

Kabouik commented 4 years ago

I'm using DejàVuSans Mono, I just adapted the path to the font in the config file. However, I tried setting my locale to en_GB.UTF-8 in my ~/.bashrc instead of the default en_GB.utf8, and now havoc is correctly displaying accented characters.

My understanding is both formats should be equally recognized/converted at some basic OS level, but maybe that is missing on SFOS. I created an issue to report it here.

Kabouik commented 4 years ago

No that's not it, I lost UTF-8 characters again in another havoc session without changing my LANG nor rebooting. I'll investigate, it's definitely on my end.

ii8 commented 4 years ago

Hm, the locale might affect whether you are able to input characters using compose, with multiple keystrokes. It shouldn't change whether printf '\xe2\x99\xa5' renders correctly.

Kabouik commented 4 years ago

You're right, the character does show up. But somehow cmus no longer displays accents, although it did when I posted here 40 min ago. And yesterday when I was still using .utf8 as my locale, the heart wouldn't display in havoc.

Screenshot_20200602_005 Screenshot_20200602_007

Also, some Node.js apps that don't use the correct character for their drawings (they do in Fingerterm, despite other bugs related to Fingerterm's redraw issue):

Screenshot_20200602_008 Screenshot_20200602_009

Kabouik commented 4 years ago

Just a follow-up of the recent progress:

I'm sorry, this is by far the longest issue you have had here, but I find the progress the last few days truly exciting.

¹ Possible icon based on that one with CC0 licence and adapted to SFOS templates:

havoc

Would it work for you?

Kabouik commented 4 years ago

I think only havoc.spec below needs some changes, the rest should be ready for OBS.

havoc.spec

Name:          havoc
Version:       85fdde7
Release:       1
Summary:       A minimal terminal emulator for Wayland on Linux
Group:         System
Vendor:        Murray Calavera <murray.calavera@protonmail.com>
Distribution:  Sailfish OS
Packager:      Kabouik <matf[redactedforbots]disr.it>
Source0:       %{name}-%{version}.tar.gz
URL:           https://github.com/ii8/havoc

License:       MIT

%description
Havoc is a minimal but modern terminal emulator for Wayland. It supports everything you would expect from a terminal emulator on a PC, including 24bit colours and TUI features that Fingerterm and, to a lower extent, Toeterm, cannot handle. Havoc being developed for PC originally, it is meant to be used in landscape with a hardware keyboard.

You can still use Havoc with no hardware keyboard, using qCommand, any other terminal, or .desktop files to print command outputs that do not render correctly in other terminals. To issue a command in Havoc from another application, use "havoc -l COMMAND", where "-l" is to hold in case the output does not keep a process running.

# Features
- 24bit colours
- Full support for ncurses features and other TUI
- Easy multi-touch text selection; no more conflict between selecting and scrolling
- One finger scrolling (like all native SFOS apps except terminals
- User configuration in ~/.config/havoc.cfg by default (font, font size, colours, opacity of the cover, etc.)
- Support for compose and dead keys if your hardware keyboard is set to use a xkb layout with those (additional package)

# Disclaimer
I am not the developer of Havoc, I just packaged it for SFOS. Havoc is being actively developed by Murray Calavera (ii8) at https://github.com/ii8/havoc/.

%license
LICENSE

%build
make CFLAGS="-O2 -DNDEBUG"

%install
make PREFIX=/usr DESTDIR=%{?buildroot} install

%config
/home/nemo/.config/havoc.cfg

%post
# Change permissions on the config file
chmod -R 755 /home/nemo/.config/havoc.cfg
chown -R nemo:nemo /home/nemo/.config/havoc.cfg

%postun

%changelog
* Sat Un 06 2020 Kabouik <matf[redactedforbots]disr.it> 85fdde7
- First SFOS package based on the 85fdde7 version.

Please keep in mind I'm not in software development at all, I don't want to mistakenly take any credit for Havoc. I put myself as packager here because I will keep using SFOS in any foreseeable future, but feel free to scrap me from the file if you want to upload on the repository yourself.

The %description part should probably just be limited to the first paragraph. The rest I can put on the webpage's longer description (it appears in the application store).

_service

<services>
  <service name="webhook">
  <param name="repourl">https://github.com/ii8/havoc.git</param>
  <param name="branch">sailfishos</param>
  </service>
<service name="tar_git">
  <param name="url">https://github.com/ii8/havoc.git</param>
  <param name="branch">sailfishos</param>
  <param name="revision">85fdde75d98d4468dceabeb81253b834c6390a82</param>
  <param name="token"/>
  <param name="debian">N</param>
  <param name="dumb">N</param>
</service></services>

/usr/share/applications/havoc.desktop

[Desktop Entry]
Type=Application
Name=Havoc
Exec=havoc bash -l
Icon=havoc

/home/nemo/.config/havoc.cfg/

[child]
# program to run in child process
program=bash

[window]
# opacity of background from 0 (fully transparent) to 255 (fully opaque)
opacity=210

# render a margin to exactly match window size hints from the compositor
margin=yes

[terminal]
# size of terminal - no effect on SFOS
rows=16
columns=140

# number of lines to keep in scrollback
scrollback=1000

[font]
# heigth of a single glyph in pixels
size=30

# absolute path to a truetype font
path=/usr/share/fonts/dejavu/DejaVuSansMono.ttf

[colors]
# Railcasts dark by Chris Kempson
foreground = #e6e1dc
background = #060a07

# black
color0  = #060a07
color8  = #5a647e

# red
color1  = #da4939
color9  = #da6b5f

# green
color2  = #a5c261
color10 = #abc277

# yellow
color3  = #ffc66d
color11 = #ffd99e

# blue
color4  = #6d9cbe
color12 = #94acbe

# magenta
color5  = #b6b3eb
color13 = #d2d0eb

# cyan
color6  = #519f50
color14 = #6a9f69

# white
color7  = #e6e1dc
color15 = #f9f4eb

And the icon should go into /usr/share/icons/hicolor/86x86/apps/havoc.png (there are folders for .svg and higher resolutions rasters too but the icon was not used when I tried there).

ii8 commented 4 years ago

We're done here. Very nice. :champagne: Port is at: https://github.com/Kabouik/havoc In the repo: https://openrepos.net/content/kabouik/havoc

The font issue, unicode block elements not fully filling cells, is separate(and very difficult to fix it seems).

Kabouik commented 4 years ago

Thanks for your continued support and patience, it was greatly appreciated and I'm sure other SFOS (or Nemo/Mer) users will benefit from the port.

Kabouik commented 3 years ago

Just a quick message to show you that the SailfishOS port didn't bring thousands of new users of course, but it seems Havoc has a steady download slope and is being used everywhere. I suspect that people who download it own a keyboard phone, and in that case there is no real competition for Havoc so they likely do use it, instead of download it just to uninstall it afterwards.

Screenshot_2020-11-12 Download Details Havoc OpenRepos net — Community Repository System