Skip to content

Commit

Permalink
Merge branch 'elfmz:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-soft authored Nov 22, 2024
2 parents f0fa790 + 63ae9f6 commit b0ca438
Show file tree
Hide file tree
Showing 97 changed files with 2,582 additions and 851 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC -Wno-unused-function -D_FILE_OFFSET_BITS=64") # -fsanitize=address
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -fPIC -Wno-unused-function -D_FILE_OFFSET_BITS=64") # -fsanitize=address
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O2")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS_RELEASE "-O2")

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(APP_DIR ${CMAKE_BINARY_DIR}/install)
Expand Down
8 changes: 4 additions & 4 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ far2l uses this to resolve symlink destination when user selects plugin's item t

### Added following dialog messages:
* `DM_SETREADONLY` - changes readonly-ness of selected dialog edit control item
* `DM_GETCOLOR` - retrieves current color attributes of selected dialog item
* `DM_SETCOLOR` - changes current color attributes of selected dialog item
* `DM_SETTRUECOLOR` - sets 24-bit RGB colors to selected dialog item, can be used within DN_CTLCOLORDLGITEM handler to provide extra coloring.
* `DM_GETTRUECOLOR` - retrieves 24-bit RGB colors of selected dialog item, if they were set before by DM_SETTRUECOLOR.
* `DM_GETDEFAULTCOLOR`
* `DM_GETCOLOR = DM_SETTRUECOLOR` - sets 24-bit RGB colors to selected dialog item (see DN_CTLCOLORDLGITEM).
* `DM_SETCOLOR = DM_GETTRUECOLOR` - retrieves 24-bit RGB colors of selected dialog item.
* `DM_SETTEXTPTRSILENT`
* `ECTL_ADDTRUECOLOR` - applies coloring to editor like ECTL_ADDCOLOR does but allows to specify 24 RGB color using EditorTrueColor structure.
* `ECTL_GETTRUECOLOR` - retrieves coloring of editor like ECTL_GETCOLOR does but gets 24 RGB color using EditorTrueColor structure.

Expand Down
60 changes: 39 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ FreeBSD/MacOS (Cirrus CI): [![Cirrus](https://api.cirrus-ci.com/github/elfmz/far
* 7z ANSI-C Decoder
* utf-cpp by ww898

<sub><a name="keyshells"></a>_Note_: Far2l uses keyboard shortcurts in the tradition of the Far Manager for Windows,
but some of them (**Alt**-**F1**, **Alt**-**F2**, **Alt**-**F7**, **Ctrl**-arrows, etc.)
usually exclusively used in desktop environment GNOME, KDE, Xfce, macOS etc. and in terminal emulators.
To work with these keys in far2l you need to _release keyboard shortcuts globally_
in the environment settings (see [#2326](https://github.com/elfmz/far2l/issues/2326))
or use far2l lifehacks:
_Sticky controls via **Ctrl**-**Space** or **Alt**-**Space**_ or _Exclusively handle hotkeys option in the Input settings_
(see details in buil-in far2l help).</sub>

### UI Backends
FAR2L has base UI Backends (see details in build-in help section **UI backends**):

Expand All @@ -42,11 +51,11 @@ FreeBSD/MacOS (Cirrus CI): [![Cirrus](https://api.cirrus-ci.com/github/elfmz/far
| **Works:** | in **console**<br>and in any<br>**terminal** | in **terminal<br>window**<br><sub>under graphic<br>X11 session</sub> | in **terminal<br>window**<br><sub>under graphic<br>X11 session</sub> | in **Desktop<br>environment**<br><sub>(X11<br>or Wayland<br>or macOS)<br>via wxWidgets</sub> |
| **Binaries:** | far2l | far2l<br>far2l_ttyx.broker | far2l<br>far2l_ttyx.broker | far2l<br>far2l_gui.so |
| **[Dependencies](#required-dependencies):** | minimal | + libx11 | + libx11, libxi | + wxWidgets, GTK |
| **Keyboard:** | <sub>_Typical terminals_:<br>**only essential<br>key combinations**<br><br>_KiTTY_ (putty fork),<br>_kitty_ (*nix one),<br>_iTerm2_,<br>_Windows Terminal_,<br>far2l’s VT: **full support**</sub> | <sub>_Typical terminals_:<br>**only essential<br>key combinations**<br><br>_KiTTY_ (putty fork),<br>_kitty_ (*nix one),<br>_iTerm2_,<br>_Windows Terminal_,<br>far2l’s VT: **full support**</sub> | <sub>_Typical terminals_:<br>**most of key<br>combinations under x11**;<br>**only essential key<br>combinations<br>under Wayland**<br><br>_KiTTY_ (putty fork),<br>_kitty_ (*nix one),<br>_iTerm2_,<br>_Windows Terminal_,<br>far2l’s VT: **full support**</sub> | **All key<br>combinations** |
| **Clipboard<br>access:** | <sub>_Typical terminals_:<br>via command line<br>tools like xclip<br><br>_kitty_ (*nix one),<br>_iTerm2_:<br>via **OSC52**<br><br>_Windows Terminal_:<br>via **OSC52**<br>or via **command line<br>tools under WSL**<br><br>_KiTTY_ (putty fork),<br>far2l’s VT:<br>via **far2l extensions**</sub> | <sub>_Typical terminals_,<br>_kitty_ (*nix one):<br>via **x11 interaction**<br><br>_iTerm2_:<br>via **OSC52**<br><br>_Windows Terminal_:<br>via **OSC52**<br>or via **command line<br>tools under WSL**<br><br>_KiTTY_ (putty fork),<br>far2l’s VT:<br>via **far2l extensions**</sub> | <sub>_Typical terminals_,<br>_kitty_ (*nix one):<br>via **x11 interaction**<br><br>_iTerm2_:<br>via **OSC52**<br><br>_Windows Terminal_:<br>via **OSC52**<br>or via **command line<br>tools under WSL**<br><br>_KiTTY_ (putty fork),<br>far2l’s VT:<br>via **far2l extensions**</sub> | via<br>**wxWidgets API**<br><br><sub>via command line<br>tools under WSL</sub> |
| **Typical<br>use case:** | **Servers**,<br>embedded<br>(*wrt, etc) | <sub>Run far2l in<br>favorite terminal<br>but with<br>**better UX**</sub> | <sub>Run far2l in<br>favorite terminal<br>but with<br>**best UX**</sub> | **Desktop** |
| [Debian](https://packages.debian.org/search?keywords=far2l) packages: | _none_<br><sup>(use `far2l` due to<br>[auto downgrade](#downgrade))</sup> | `far2l` | `far2l` | `far2l-wx`<br><sup>(since _2.6.4_)</sup> |
| [Ubuntu](https://packages.ubuntu.com/search?keywords=far2l) packages: | _none_<br><sup>(use `far2l` due to<br>[auto downgrade](#downgrade))</sup> | `far2l` | `far2l` | _none_ |
| **Keyboard:** | <sub>_Typical terminals_:<br>**only essential<br>key combinations**<br><br>_KiTTY_ (putty fork),<br>_kitty_ (\*nix one),<br>_iTerm2_,<br>_Windows Terminal_,<br>far2l’s VT: **full support**</sub> | <sub>_Typical terminals_:<br>**only essential<br>key combinations**<br><br>_KiTTY_ (putty fork),<br>_kitty_ (\*nix one),<br>_iTerm2_,<br>_Windows Terminal_,<br>far2l’s VT: **full support**</sub> | <sub>_Typical terminals_:<br>**most of key<br>combinations under x11**;<br>**only essential key<br>combinations<br>under Wayland**<br><br>_KiTTY_ (putty fork),<br>_kitty_ (\*nix one),<br>_iTerm2_,<br>_Windows Terminal_,<br>far2l’s VT: **full support**</sub> | **All key<br>combinations** |
| **Clipboard<br>access:** | <sub>_Typical terminals_:<br>via command line<br>tools like xclip<br><br>_kitty_ (\*nix one),<br>_iTerm2_:<br>via **OSC52**<br><br>_Windows Terminal_:<br>via **OSC52**<br>or via **command line<br>tools under WSL**<br><br>_KiTTY_ (putty fork),<br>far2l’s VT:<br>via **far2l extensions**</sub> | <sub>_Typical terminals_,<br>_kitty_ (\*nix one):<br>via **x11 interaction**<br><br>_iTerm2_:<br>via **OSC52**<br><br>_Windows Terminal_:<br>via **OSC52**<br>or via **command line<br>tools under WSL**<br><br>_KiTTY_ (putty fork),<br>far2l’s VT:<br>via **far2l extensions**</sub> | <sub>_Typical terminals_,<br>_kitty_ (\*nix one):<br>via **x11 interaction**<br><br>_iTerm2_:<br>via **OSC52**<br><br>_Windows Terminal_:<br>via **OSC52**<br>or via **command line<br>tools under WSL**<br><br>_KiTTY_ (putty fork),<br>far2l’s VT:<br>via **far2l extensions**</sub> | via<br>**wxWidgets API**<br><br><sub>via command line<br>tools under WSL</sub> |
| **Typical<br>use case:** | **Servers**,<br>embedded<br>(\*wrt, etc) | <sub>Run far2l in<br>favorite terminal<br>but with<br>**better UX**</sub> | <sub>Run far2l in<br>favorite terminal<br>but with<br>**best UX**</sub> | **Desktop** |
| [Debian](#debian) packages: | _none_<br><sup>(use `far2l` due to<br>[auto downgrade](#downgrade))</sup> | `far2l` | `far2l` | `far2l-wx`<br><sup>(since _2.6.4_)</sup> |
| [Ubuntu](#debian) packages: | _none_<br><sup>(use `far2l` due to<br>[auto downgrade](#downgrade))</sup> | `far2l` | `far2l` | _none_ |
| Community [PPA](#community_bins): | `far2l` | `far2l-ttyx` | `far2l-ttyx` | `far2l-gui` |

<sub><a name="downgrade"></a>_Note_: When running far2l automatically downgrade
Expand All @@ -61,14 +70,15 @@ for plain **TTY**: `far2l --tty --nodetect=x`

<sub>_Note about use OSC 52 in TTY/TTY|X_:
to interact with the system clipboard you must **not forget to enable OSC 52**
in both the **FAR2L settings** (`Options`->`Interface settings`->`Use OSC52 to set clipboard data`,
in both the **FAR2L settings** (`Options``Interface settings``Use OSC52 to set clipboard data`,
which shown in the dialog only if far2l run in TTY/TTY|X mode and all other options for clipboard access are unavailable;
you can run `far2l --tty --nodetect` to force not use others clipboard options),
and in **terminal settings** option OSC 52 must be allowed (by default, OSC 52 is disabled in some terminals for security reasons;
OSC 52 in many terminals is implemented only for the copy mode, and paste from the terminal goes by bracketed paste mode).</sub>


## Installing, Running
<a name="debian"></a>
#### Debian/Ubuntu binaries from the official repositories

* **TTY X/Xi** backends only (Debian / Ubuntu 23.10+)
Expand All @@ -88,6 +98,23 @@ https://packages.debian.org/search?keywords=far2l or https://packages.ubuntu.com
<sub>_Note_: binaries in official repositories may be very outdated,
actual binaries or portable see in [Community packages & binaries](#community_bins).</sub>

<details><summary>Backport official packages for old Debian/Ubuntu system</summary>

<sub>A simple sid back port should be as easy as (build your own binary deb from the official source deb package,
required install [dependencies](#required-dependencies)):</sub>

```sh
# you will find the latest dsc link at http://packages.debian.org/sid/far2l
dget http://deb.debian.org/debian/pool/main/f/far2l/2.6.3~beta+ds-1.dsc
dpkg-source -x *.dsc
cd far2l-*/
debuild
# cd .. and install your self built far2l*.deb
```

</details>


#### OSX/MacOS binaries

You can install prebuilt package for x86_64 platform via Homebrew Cask, by command:
Expand Down Expand Up @@ -122,7 +149,7 @@ See also [Community packages & binaries](#community_bins)
* `libnfs-dev` (_optional_ - needed for **NetRocks/NFS**)
* `libneon27-dev` (or later, _optional_ - needed for **NetRocks/WebDAV**)
* `libarchive-dev` (_optional_ - needed for better archives support in **multiarc**)
* `libunrar-dev` (_optional_ - needed for RAR archives support in **multiarc**, see `UNRAR` command line option)
* `libunrar-dev` (_optional_ - needed for RAR archives support in **multiarc**, see `-DUNRAR` command line option)
* `libpcre2-dev` (_optional_ - needed for advanced custom archive formats support in **multiarc**)
* `python3-dev` (_optional_ - needed for **python plugins** support, see `-DPYTHON` command line option)
* `python3-cffi` (_optional_ - needed for **python plugins** support, see `-DPYTHON` command line option)
Expand All @@ -131,22 +158,12 @@ See also [Community packages & binaries](#community_bins)
* `g++`
* `git` (needed for downloading source code)

#### Or simply on Debian/Ubuntu:
or simply on **Debian/Ubuntu**:
``` sh
apt-get install libwxgtk3.0-gtk3-dev libx11-dev libxi-dev libpcre2-dev libxml2-dev libuchardet-dev libssh-dev libssl-dev libsmbclient-dev libnfs-dev libneon27-dev libarchive-dev cmake pkg-config g++ git
```

A simple sid back port should be as easy as (build your own binary deb from the official source deb package):
```sh
# you will find the latest dsc link at http://packages.debian.org/sid/far2l
dget http://deb.debian.org/debian/pool/main/f/far2l/far2l_2.5.0~beta+git20230223+ds-2.dsc
dpkg-source -x *.dsc
cd far2l-*/
debuild
# cd .. and install your self built far2l*.deb
```

In older distributions: use libwxgtk3.0-dev instead of libwxgtk3.0-gtk3-dev
In older distributions: use `libwxgtk3.0-dev` instead of `libwxgtk3.0-gtk3-dev`.

#### Clone and Build
* Clone current master
Expand Down Expand Up @@ -313,7 +330,7 @@ You can import the project into your favourite IDE like QtCreator, CodeLite, or
## Terminals and SSH clients
Supporting extended far2l keyboard shortcuts and clipboard access
* **kovidgoyal's kitty** (Linux, macOS, *BSD): https://github.com/kovidgoyal/kitty & https://sw.kovidgoyal.net/kitty (TTY|k backend: keys by kovidgoyal's kitty keyboard protocol; turn on OSC 52 in far2l and kitty for clipboard support)
* **kovidgoyal's kitty** (Linux, macOS, \*BSD): https://github.com/kovidgoyal/kitty & https://sw.kovidgoyal.net/kitty (TTY|k backend: keys by kovidgoyal's kitty keyboard protocol; turn on OSC 52 in far2l and kitty for clipboard support)
* **Wez's Terminal Emulator** (Linux, FreeBSD, Windows): https://github.com/wez/wezterm & https://wezfurlong.org/wezterm (TTY|k backend: keys in Linux, FreeBSD by kovidgoyal's kitty keyboard protocol; TTY|w backend: keys in Windows by win32-input-mode, enabled by default; turn on OSC 52 for clipboard support) [kitty keyboard protocol not supported in macOS & Windows]
* **iTerm2** (macOS): https://gitlab.com/gnachman/iterm2 & https://iterm2.com (TTY|a backend: keys by iTerm2 "raw keyboard" protocol; turn on OSC 52 for clipboard support)
* **Windows Terminal** (TTY|w backend: keys by win32-input-mode; turn on OSC 52 for clipboard support; has mouse bug: https://github.com/microsoft/terminal/issues/15083 )
Expand All @@ -332,7 +349,8 @@ one of the best way to initiate the connection **inside local far2l-GUI**
* A collection of macros for far2l: https://github.com/corporateshark/far2l-macros
* Turbo Vision, TUI framework supporting far2l terminal extensions: https://github.com/magiblot/tvision
* turbo, text editor supporting far2l terminal extensions: https://github.com/magiblot/turbo
* Tool to import color schemes from windows FAR manager 2 .reg format: https://github.com/unxed/far2ltricks/blob/main/misc/far2l_import.pl
* far2ltricks: https://github.com/unxed/far2ltricks
* tool to import color schemes from windows FAR manager 2 .reg format: https://github.com/unxed/far2ltricks/blob/main/misc/far2l_import.pl
* **Community wiki & tips** (in Russian; unofficial): https://github.com/akruphi/far2l/wiki
Expand Down
27 changes: 17 additions & 10 deletions WinPort/src/APITime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,11 @@ WINPORT_DECL(DosDateTimeToFileTime, BOOL, ( WORD fatdate, WORD fattime, LPFILETI

static unsigned s_time_failmask = 0;

WINPORT_DECL(GetTickCount, DWORD, ())
static DWORD64 GetTickCountInner()
{
(void)s_time_failmask;
#ifdef _WIN32
return ::GetTickCount();
return ::GetTickCount64();
#elif defined(__APPLE__)
static mach_timebase_info_data_t g_timebase_info;
if (g_timebase_info.denom == 0)
Expand All @@ -397,9 +397,9 @@ WINPORT_DECL(GetTickCount, DWORD, ())
# else
if (LIKELY(clock_gettime(CLOCK_REALTIME_COARSE, &spec) == 0)) {
# endif
DWORD rv = spec.tv_sec;
DWORD64 rv = spec.tv_sec;
rv*= 1000;
rv+= (DWORD)(spec.tv_nsec / 1000000);
rv+= (DWORD64)(spec.tv_nsec / 1000000);
return rv;
}
fprintf(stderr, "%s: clock_gettime error %u\n", __FUNCTION__, errno);
Expand All @@ -409,19 +409,25 @@ WINPORT_DECL(GetTickCount, DWORD, ())
if (LIKELY((s_time_failmask & 2) == 0)) {
struct timeval tv{};
if (LIKELY(gettimeofday(&tv, NULL) == 0)) {
DWORD rv = tv.tv_sec;
DWORD64 rv = tv.tv_sec;
rv*= 1000;
rv+= (DWORD)(tv.tv_usec / 1000);
rv+= (DWORD64)(tv.tv_usec / 1000);
return rv;
}
fprintf(stderr, "%s: gettimeofday error %u\n", __FUNCTION__, errno);
s_time_failmask|= 2;
}

return DWORD(time(NULL) * 1000);
return DWORD64(time(NULL) * 1000);
#endif
}

WINPORT_DECL(GetTickCount, DWORD, ())
{
DWORD out = (DWORD)GetTickCountInner();
return LIKELY(out != 0) ? out : 1;
}

WINPORT_DECL(Sleep, VOID, (DWORD dwMilliseconds))
{
#ifdef _WIN32
Expand All @@ -436,10 +442,11 @@ WINPORT_DECL(Sleep, VOID, (DWORD dwMilliseconds))
#endif
}

static clock_t g_process_start_stamp = WINPORT(GetTickCount)();
static DWORD64 g_process_start_stamp = GetTickCountInner();

SHAREDSYMBOL clock_t GetProcessUptimeMSec()
{
clock_t now = WINPORT(GetTickCount)();
return (now - g_process_start_stamp);
clock_t out = (clock_t)(GetTickCountInner() - g_process_start_stamp);
return LIKELY(out != 0) ? out : 1;
}

23 changes: 21 additions & 2 deletions WinPort/src/Backend/TTY/TTYBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,36 @@ TTYBackend::~TTYBackend()
DetachNotifyPipe();
}

static unsigned short GetWinSizeEnv(const char *env, unsigned short def)
{
const char *psz = getenv(env);
if (psz && *psz) { // use it if it contains sane integer value
int v = atoi(psz);
if (v > 10 && v < 4096) {
return (unsigned short)v;
}
}
return def;
}

void TTYBackend::GetWinSize(struct winsize &w)
{
int r = ioctl(_stdout, TIOCGWINSZ, &w);
if (UNLIKELY(r != 0)) {
r = ioctl(_stdin, TIOCGWINSZ, &w);
if (UNLIKELY(r != 0)) {
perror("TIOCGWINSZ");
w.ws_row = g_far2l_term_height;
w.ws_col = g_far2l_term_width;
}
}
if (UNLIKELY(r != 0) || (w.ws_row == 0 && w.ws_col == 0)) {
// when running over serial console 0:0 is returned always and far2l unusable
// try to use $LINES and $COLUMNS if they contain sane values,
// otherwise fallback to hardcoded 80:25
w.ws_row = GetWinSizeEnv("LINES", g_far2l_term_height);
w.ws_col = GetWinSizeEnv("COLUMNS", g_far2l_term_width);
fprintf(stderr, "%s: fallback size %u:%u\n",
__FUNCTION__, (unsigned int)w.ws_row, (unsigned int)w.ws_col);
}
}

void TTYBackend::DetachNotifyPipe()
Expand Down
15 changes: 14 additions & 1 deletion WinPort/src/Backend/TTY/TTYInputSequenceParserExts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,26 @@ size_t TTYInputSequenceParser::TryParseAsKittyEscapeSequence(const char *s, size
if ((modif_state & KITTY_MOD_CAPSLOCK) && !(modif_state & KITTY_MOD_SHIFT)) {
// it's weird, but kitty can not give us uppercase utf8 in caps lock mode
// ("text-as-codepoints" mode should solve it, but it is not working for cyrillic chars for unknown reason)
ir.Event.KeyEvent.uChar.UnicodeChar = towupper(ir.Event.KeyEvent.uChar.UnicodeChar);
// ir.Event.KeyEvent.uChar.UnicodeChar = towupper(ir.Event.KeyEvent.uChar.UnicodeChar);
WINPORT(CharUpperBuff)(&ir.Event.KeyEvent.uChar.UnicodeChar, 1);
}

ir.Event.KeyEvent.bKeyDown = (event_type != KITTY_EVT_KEYUP) ? 1 : 0;

ir.Event.KeyEvent.wRepeatCount = 0;

if ((ir.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED) ||
(ir.Event.KeyEvent.dwControlKeyState & RIGHT_ALT_PRESSED)) {
switch (ir.Event.KeyEvent.wVirtualKeyCode) {
case VK_ESCAPE: case VK_DELETE: case VK_BACK: case VK_TAB: case VK_RETURN: case VK_SPACE:
break;
default:
if (ir.Event.KeyEvent.uChar.UnicodeChar > 0) {
WINPORT(CharUpperBuff)(&ir.Event.KeyEvent.uChar.UnicodeChar, 1);
}
}
}

_ir_pending.emplace_back(ir);

if (!_using_extension) {
Expand Down
Loading

0 comments on commit b0ca438

Please sign in to comment.