57e8c959a02ca8c2aeda3980480a50a1f82f6953

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

style(installer): use rainbow logo and polish success message (#10211)

Diff

This diff is truncated to protect this page.

  1diff --git a/tools/install.sh b/tools/install.sh
  2index 510f83ce84b4d1d804ae7d335862498207fbb93c..7704107c82dbf6ad2d5530d9a4672723a2d98b66 100755
  3--- a/tools/install.sh
  4+++ b/tools/install.sh
  5@@ -56,22 +56,115 @@ command_exists() {
  6   command -v "$@" >/dev/null 2>&1
  7 }
  8 
  9-fmt_error() {
 10-  printf '%sError: %s%s\n' "$BOLD$RED" "$*" "$RESET" >&2
 11+# The [ -t 1 ] check only works when the function is not called from
 12+# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
 13+# function at the top level to always return false when stdout is not
 14+# a tty.
 15+if [ -t 1 ]; then
 16+  is_tty() {
 17+    true
 18+  }
 19+else
 20+  is_tty() {
 21+    false
 22+  }
 23+fi
 24+
 25+# This function uses the logic from supports-hyperlinks[1][2], which is
 26+# made by Kat Marchán (@zkat) and licensed under the Apache License 2.0.
 27+# [1] https://github.com/zkat/supports-hyperlinks
 28+# [2] https://crates.io/crates/supports-hyperlinks
 29+#
 30+# Copyright (c) 2021 Kat Marchán
 31+#
 32+# Licensed under the Apache License, Version 2.0 (the "License");
 33+# you may not use this file except in compliance with the License.
 34+# You may obtain a copy of the License at
 35+#
 36+#     http://www.apache.org/licenses/LICENSE-2.0
 37+#
 38+# Unless required by applicable law or agreed to in writing, software
 39+# distributed under the License is distributed on an "AS IS" BASIS,
 40+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 41+# See the License for the specific language governing permissions and
 42+# limitations under the License.
 43+supports_hyperlinks() {
 44+  # $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass)
 45+  if [ -n "$FORCE_HYPERLINK" ]; then
 46+    [ "$FORCE_HYPERLINK" != 0 ]
 47+    return $?
 48+  fi
 49+
 50+  # If stdout is not a tty, it doesn't support hyperlinks
 51+  is_tty || return 1
 52+
 53+  # DomTerm terminal emulator (domterm.org)
 54+  if [ -n "$DOMTERM" ]; then
 55+    return 0
 56+  fi
 57+
 58+  # VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc)
 59+  if [ -n "$VTE_VERSION" ]; then
 60+    [ $VTE_VERSION -ge 5000 ]
 61+    return $?
 62+  fi
 63+
 64+  # If $TERM_PROGRAM is set, these terminals support hyperlinks
 65+  case "$TERM_PROGRAM" in
 66+  Hyper|iTerm.app|terminology|WezTerm) return 0 ;;
 67+  esac
 68+
 69+  # kitty supports hyperlinks
 70+  if [ "$TERM" = xterm-kitty ]; then
 71+    return 0
 72+  fi
 73+
 74+  # Windows Terminal or Konsole also support hyperlinks
 75+  if [ -n "$WT_SESSION" ] || [ -n "$KONSOLE_VERSION" ]; then
 76+    return 0
 77+  fi
 78+
 79+  return 1
 80+}
 81+
 82+fmt_link() {
 83+  # $1: text, $2: url, $3: fallback mode
 84+  if supports_hyperlinks; then
 85+    printf '\033]8;;%s\a%s\033]8;;\a\n' "$2" "$1"
 86+    return
 87+  fi
 88+
 89+  case "$3" in
 90+  --text) printf '%s\n' "$1" ;;
 91+  --url|*) fmt_underline "$2" ;;
 92+  esac
 93 }
 94 
 95 fmt_underline() {
 96-  printf '\033[4m%s\033[24m\n' "$*"
 97+  is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*"
 98 }
 99 
100+# shellcheck disable=SC2016 # backtick in single-quote
101 fmt_code() {
102-  # shellcheck disable=SC2016 # backtick in single-quote
103-  printf '`\033[38;5;247m%s%s`\n' "$*" "$RESET"
104+  is_tty && printf '`\033[2m%s\033[22m`\n' "$*" || printf '`%s`\n' "$*"