Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lib/gdb.sh: syntax highlight for .sh.command

lib/msg.sh:  Error messages are italic.
lib/term-hightlight.py: Remove Python warnings in import
Sync with bashdb
  • Loading branch information...
commit 41c48a6ed4c6f0593abd1ba87b856987cfc1c31e 1 parent ee1e934
@rocky authored
View
2  command/set_sub/highlight.sh
@@ -42,9 +42,7 @@ _Dbg_do_set_highlight() {
reset )
_Dbg_set_highlight=1
_Dbg_filecache_reset
- set -x
_Dbg_readin $_Dbg_frame_last_filename
- set +x
;;
* )
_Dbg_errmsg '"on", "off", or "reset" expected.'
View
12 lib/filecache.sh
@@ -35,12 +35,12 @@ _Dbg_file2canonic=()
function _Dbg_readfile # var file
{
- nameref var=$1
- typeset old_IFS="$IFS"
- set -f
- IFS=$'\n\n' var=( $(< $2))
- set +f
- IFS="$old_IFS"
+ nameref var=$1
+ typeset old_IFS="$IFS"
+ set -f
+ IFS=$'\n\n' var=( $(< $2))
+ set +f
+ IFS="$old_IFS"
}
Fileinfo_t -A _Dbg_filenames
View
10 lib/gdb.sh
@@ -35,7 +35,13 @@ function _Dbg_print_location {
}
function _Dbg_print_command {
- _Dbg_msg ${.sh.command}
+ typeset msg
+ if (( _Dbg_set_highlight )) ; then
+ msg=$(echo ${.sh.command} | python lib/term-highlight.py)
+ else
+ msg=${.sh.command}
+ fi
+ _Dbg_msg "$msg"
}
function _Dbg_print_location_and_command {
@@ -44,7 +50,7 @@ function _Dbg_print_location_and_command {
# typeset -i new_level
# ((new_level=${#_Dbg_frame_stack[@]} - 1 - $_Dbg_stack_pos))
# (( .sh.level = new_level ))
- _Dbg_msg ${.sh.command}
+ _Dbg_print_command
# (( .sh.level = ${.old_level} ))
}
View
115 lib/msg.sh
@@ -2,19 +2,25 @@
#
# Copyright (C) 2008, 2009 Rocky Bernstein rocky@gnu.org
#
-# kshdb is free software; you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free
-# Software Foundation; either version 2, or (at your option) any later
-# version.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or
+# (at your option) any later version.
#
-# kshdb is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with kshdb; see the file COPYING. If not, write to the Free Software
-# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to
+# the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
+# MA 02111 USA.
+
+_Dbg_ansi_term_bold=""
+_Dbg_ansi_term_italic=""
+_Dbg_ansi_term_underline=""
+_Dbg_ansi_term_normal=""
# Called when a dangerous action is about to be done to make sure it's
# okay. `prompt' is printed, and "yes", or "no" is solicited. The
@@ -23,70 +29,79 @@
#
_Dbg_confirm() {
if (( $# < 1 || $# > 2 )) ; then
- _Dbg_response='error'
- return 0
+ _Dbg_response='error'
+ return 0
fi
- typeset _Dbg_confirm_prompt=$1
- typeset _Dbg_confirm_default=${2:-'no'}
- typeset -l _Dbg_response
+ typeset _Dbg_confirm_prompt; _Dbg_confirm_prompt=$1
+ typeset _Dbg_confirm_default; _Dbg_confirm_default=${2:-'no'}
+ typeset _Dbg_response
while read "_Dbg_response?$_Dbg_confirm_prompt" args <&${_Dbg_fd[_Dbg_fd_last]}
do
- case "$_Dbg_response" in
- 'y' | 'yes' | 'yeah' | 'ya' | 'ja' | 'si' | 'oui' | 'ok' | 'okay' )
- _Dbg_response='y'
- return 0
- ;;
- 'n' | 'no' | 'nope' | 'nyet' | 'nein' | 'non' )
- _Dbg_response='n'
- return 0
- ;;
- *)
- if [[ $_Dbg_response =~ ^[ \t]*$ ]] ; then
- _Dbg_response=$_Dbg_confirm_default
- return 0
- else
- _Dbg_msg "I don't understand \"$_Dbg_response\"."
- _Dbg_msg "Please try again entering 'yes' or 'no'."
- fi
- ;;
- esac
+ case "$_Dbg_response" in
+ 'y' | 'yes' | 'yeah' | 'ya' | 'ja' | 'si' | 'oui' | 'ok' | 'okay' )
+ _Dbg_response='y'
+ return 0
+ ;;
+ 'n' | 'no' | 'nope' | 'nyet' | 'nein' | 'non' )
+ _Dbg_response='n'
+ return 0
+ ;;
+ *)
+ if [[ $_Dbg_response =~ ^[ \t]*$ ]] ; then
+ _Dbg_response=$_Dbg_confirm_default
+ return 0
+ else
+ _Dbg_msg "I don't understand \"$_Dbg_response\"."
+ _Dbg_msg "Please try again entering 'yes' or 'no'."
+ _Dbg_response=''
+ fi
+ ;;
+ esac
done
}
+# Print an error message
function _Dbg_errmsg {
typeset -r prefix='**'
- _Dbg_msg "$prefix $@"
+ if (( _Dbg_set_highlight )) ; then
+ _Dbg_msg "$prefix ${_Dbg_ansi_term_underline}$@${_Dbg_ansi_term_normal}"
+ else
+ _Dbg_msg "$prefix $@"
+ fi
}
+# Print an error message without the ending carriage return
function _Dbg_errmsg_no_cr {
typeset -r prefix='**'
_Dbg_msg_no_cr "$prefix $@"
}
+# print message to output device
function _Dbg_msg {
print -r -- "$@"
}
+# print message to output device without a carriage return at the end
function _Dbg_msg_nocr {
echo -n "$@"
}
# print message to output device
function _Dbg_printf {
- typeset format=$1
- shift
- if (( _Dbg_logging )) ; then
- printf "$format" "$@" >>$_Dbg_logfid
- fi
- if (( ! _Dbg_logging_redirect )) ; then
- if [[ -n $_Dbg_tty ]] ; then
- printf "$format" "$@" >>$_Dbg_tty
- else
- printf "$format" "$@"
+ typeset format=$1
+ shift
+ if (( _Dbg_logging )) ; then
+ printf "$format" "$@" >>$_Dbg_logfid
fi
- fi
- _Dbg_msg ''
+ if (( ! _Dbg_logging_redirect )) ; then
+ if [[ -n $_Dbg_tty ]] ; then
+ printf "$format" "$@" >>$_Dbg_tty
+ else
+ printf "$format" "$@"
+ fi
+ fi
+ _Dbg_msg ''
}
# print message to output device without a carriage return at the end
@@ -108,8 +123,8 @@ function _Dbg_printf_nocr {
# Common funnel for "Undefined command" message
_Dbg_undefined_cmd() {
if (( $# == 2 )) ; then
- _Dbg_msg "Undefined $1 subcommand \"$2\". Try \"help $1\"."
+ _Dbg_errmsg "Undefined $1 subcommand \"$2\". Try \"help $1\"."
else
- _Dbg_msg "Undefined command \"$1\". Try \"help\"."
+ _Dbg_errmsg "Undefined command \"$1\". Try \"help\"."
fi
}
View
17 lib/term-highlight.py
@@ -1,13 +1,16 @@
#!/usr/bin/env python
# from pydbgr.api import debug
# debug()
-from pygments import highlight
-from pygments.lexers import BashLexer
-from pygments.formatters import TerminalFormatter
-from pygments.token import Keyword, Name, Comment, String, Error, \
- Number, Operator, Generic, Token, Whitespace
-from tempfile import mktemp
-import os, sys
+import warnings
+with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ from pygments import highlight
+ from pygments.lexers import BashLexer
+ from pygments.formatters import TerminalFormatter
+ from pygments.token import Keyword, Name, Comment, String, Error, \
+ Number, Operator, Generic, Token, Whitespace
+ from tempfile import mktemp
+ import os, sys
#: Map token types to a tuple of color values for light and dark
#: backgrounds.
View
6 test/data/setshow.right
@@ -11,7 +11,7 @@ set -xv
annotate autolist copying directories history version
args basename debug editing listsize warranty
+another-bad-command
-Undefined command "another-bad-command". Try "help".
+** Undefined command "another-bad-command". Try "help".
+#### *** GNU things...
+# show warranty
+show copying
@@ -302,7 +302,7 @@ Argument list to give script when debugged program starts is:
Argument list to give script when debugged program starts is:
"now is the time".
+set misspelled 40
-Undefined set subcommand "misspelled". Try "help set".
+** Undefined set subcommand "misspelled". Try "help set".
+set listsize 40
+set listsize bad
** Integer argument expected; got: bad
@@ -341,6 +341,6 @@ $? is 0
+set autoeval off
Evaluate unrecognized commands is off.
+xx=1 ; typeset -p xx
-Undefined command "xx=1". Try "help".
+** Undefined command "xx=1". Try "help".
+quit
kshdb: That's all, folks...
View
4 test/unit/test-msg.sh.in
@@ -23,9 +23,9 @@ test_undefined()
{
typeset msg
msg=$(_Dbg_undefined_cmd foo bar)
- assertEquals 'Undefined foo subcommand "bar". Try "help foo".' "$msg"
+ assertEquals '** Undefined foo subcommand "bar". Try "help foo".' "$msg"
msg=$(_Dbg_undefined_cmd foo)
- assertEquals 'Undefined command "foo". Try "help".' "$msg"
+ assertEquals '** Undefined command "foo". Try "help".' "$msg"
}
abs_top_srcdir=@abs_top_srcdir@
Please sign in to comment.
Something went wrong with that request. Please try again.