2 Commits

Author SHA1 Message Date
  Alois Mahdal b00d06dfe4 Bump version 5 years ago
  Alois Mahdal 4112218fac Add legacy mode to avoid Term::ANSIColor dependency on RHEL-6 5 years ago
3 changed files with 21 additions and 2 deletions
  1. 1
    1
      mkit.ini
  2. 6
    0
      packaging/template.spec
  3. 14
    1
      src/include-sh/coerce.sh

+ 1
- 1
mkit.ini View File

@@ -1,5 +1,5 @@
1 1
 [project]
2
-    version     = 0.10.15
2
+    version     = 0.10.16
3 3
     codename    = FloatingPointError
4 4
     name        = Shellfu
5 5
     tagline     = Shell dot on steroids

+ 6
- 0
packaging/template.spec View File

@@ -1,7 +1,9 @@
1 1
 %if ( 0%{?rhel} && 0%{?rhel} < 7 ) || ( 0%{?centos} && 0%{?centos} < 7 )
2 2
 %global pspkg procps
3
+%global legacy true
3 4
 %else
4 5
 %global pspkg procps-ng
6
+%global legacy false
5 7
 %endif
6 8
 
7 9
 Name:           __MKIT_PROJ_PKGNAME__
@@ -100,7 +102,9 @@ interactive terminal menus
100 102
 %package sh-coerce
101 103
 Summary: Shellfu/sh module with data coercion helpers
102 104
 Requires: perl
105
+%if %{legacy} == "false"
103 106
 Requires: perl-Term-ANSIColor
107
+%endif
104 108
 Requires: shellfu-sh
105 109
 %description sh-coerce
106 110
 This sub-package contains 'coerce', Shellfu module containing few
@@ -138,6 +142,8 @@ common ANSI color names.
138 142
 
139 143
 %prep
140 144
 %setup -q
145
+/bin/sed -i '/^__COERCE__LEGACY=/s/:-false/:-%{legacy}/' ./src/include-sh/coerce.sh
146
+
141 147
 
142 148
 %build
143 149
 make %{?_smp_mflags} PREFIX=/usr

+ 14
- 1
src/include-sh/coerce.sh View File

@@ -16,7 +16,11 @@ coerce__nocolor() {
16 16
     #
17 17
     # Remove ANSI color codes
18 18
     #
19
-    perl -CS -Mutf8 -MTerm::ANSIColor=colorstrip -ne 'print colorstrip $_;'
19
+    if $__COERCE__LEGACY; then
20
+        sed 's/\x1b\[[0-9;]*m//g'
21
+    else
22
+        perl -CS -Mutf8 -MTerm::ANSIColor=colorstrip -ne 'print colorstrip $_;'
23
+    fi
20 24
 }
21 25
 
22 26
 coerce__noctl() {
@@ -66,6 +70,15 @@ coerce__for_yaml() {
66 70
     perl -CS -Mutf8 -pe "tr/$(__coerce__for_yaml_bad)/$COERCE__REPCHAR/"
67 71
 }
68 72
 
73
+#
74
+# Legacy mode
75
+#
76
+# If 'true', avoids using Term::ANSIColor in favor of a local hacky
77
+# sed expression yanked from stackoverflow.  Use if Term::ANSIColor
78
+# is not available (as is case of eg. RHEL-6).
79
+#
80
+__COERCE__LEGACY=${__COERCE__LEGACY:-false}
81
+
69 82
 __coerce__for_yaml_bad() {
70 83
     #
71 84
     # Print all YAML-bad chars