diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70df7e2..23bcbe8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: run: v install vglyph - name: Install C development dependencies (headers and libs) if: runner.os == 'Linux' - run: v retry -- sudo apt -qq update && v retry -- sudo apt install libpango1.0-dev libfontconfig1-dev libfribidi-dev libharfbuzz-dev libfreetype-dev libgl1-mesa-dri xvfb libxcursor-dev libxi-dev libxrandr-dev freeglut3-dev + run: v retry -- sudo apt -qq update && v retry -- sudo apt install libpango1.0-dev libfontconfig1-dev libfribidi-dev libharfbuzz-dev libfreetype-dev libgl1-mesa-dri xvfb libxcursor-dev libxi-dev libxrandr-dev freeglut3-dev dbus libdbus-1-dev libdbus-glib-1-2 libdbus-glib-1-dev - name: Install development dependencies on macos (headers and libs) if: runner.os == 'macOS' run: v retry -- brew install pango harfbuzz freetype2 @@ -68,7 +68,7 @@ jobs: run: v install vglyph - name: Install X11/GL development dependencies (headers and libs) if: runner.os == 'Linux' - run: v retry -- sudo apt -qq update && v retry -- sudo apt install libpango1.0-dev libfontconfig1-dev libfribidi-dev libharfbuzz-dev libfreetype-dev libgl1-mesa-dri xvfb libxcursor-dev libxi-dev libxrandr-dev freeglut3-dev + run: v retry -- sudo apt -qq update && v retry -- sudo apt install libpango1.0-dev libfontconfig1-dev libfribidi-dev libharfbuzz-dev libfreetype-dev libgl1-mesa-dri xvfb libxcursor-dev libxi-dev libxrandr-dev freeglut3-dev dbus libdbus-1-dev libdbus-glib-1-2 libdbus-glib-1-dev - name: Install development dependencies on macos (headers and libs) if: runner.os == 'macOS' run: v retry -- brew install pango harfbuzz freetype2 diff --git a/view_text_xtra.v b/view_text_xtra.v index ad467e0..26f9a17 100644 --- a/view_text_xtra.v +++ b/view_text_xtra.v @@ -9,6 +9,7 @@ module gui // import clipboard import encoding.utf8 +import os import vglyph // text_width calculates the width of a given text based on its style and window configuration, @@ -418,21 +419,38 @@ fn collapse_spaces(text string) string { // from_clipboard retrieves text content from the system clipboard and returns // it as a string. Creates a temporary clipboard instance that is automatically -// freed after the paste operation completes. +// freed after the paste operation completes. Returns empty string if clipboard +// is unavailable. pub fn from_clipboard() string { + $if !android && !ios { + if os.getenv('DISPLAY') == '' && os.getenv('WAYLAND_DISPLAY') == '' { + return '' + } + } mut cb := clipboard.new() defer { cb.free() } + if !cb.is_available() { + return '' + } return cb.paste() } // to_clipboard copies the provided string to the system clipboard if a value // is present. Creates a temporary clipboard instance that is automatically // freed after the copy operation completes. Returns true if the copy operation -// was successful, false if the input was none. +// was successful, false if the input was none or clipboard unavailable. pub fn to_clipboard(s ?string) bool { if s != none { + $if !android && !ios { + if os.getenv('DISPLAY') == '' && os.getenv('WAYLAND_DISPLAY') == '' { + return false + } + } mut cb := clipboard.new() defer { cb.free() } + if !cb.is_available() { + return false + } return cb.copy(s) } return false