# ==============================================================================
# portsreinstall library script
# - Messages -
-# Copyright (C) 2013 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
+# Copyright (C) 2013-2016 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
# This software is distributed under the 2-Clause BSD License.
# ==============================================================================
+# ============= Simple query by y (yes) or n (no) where yes by default =============
+message_query_yn_default_yes ()
+{
+ local answer
+ read answer || :
+ case `echo "$answer" | head -c 1` in
+ y|Y) message_echo
+ return 0
+ ;;
+ n|N) message_echo
+ return 1
+ ;;
+ '') return 0
+ ;;
+ *) message_echo
+ message_echo 'Pardon? ([y]/n)'
+ message_query_yn_default_yes
+ ;;
+ esac
+}
+
# ============= Simple query by y (yes) or n (no) where no by default =============
message_query_yn_default_no ()
{
+ local answer
read answer || :
case `echo "$answer" | head -c 1` in
y|Y) message_echo
# ============= Output the version =============
message_version ()
{
- [ $opt_batch_mode = no ] && echo -n "${APPNAME} version "
+ [ "x$opt_batch_mode" = xno ] && echo -n "${APPNAME} version "
echo "${MYVERSION}"
}
# ============= Output a message except for the batch mode =============
message_echo ()
{
- [ $opt_batch_mode = yes ] && return
+ [ "x$opt_batch_mode" = xyes ] && return
echo "$@" | fold -s -w `misc_get_console_column_size`
}
# ============= Output a message from stdin except for the batch mode =============
-# Input must be given via descriptor 3 if no file is given as the argument.
+# Use via pipe or redirection without argument is discouraged because it violates the screen size detection.
message_cat ()
{
local ncolumns
- [ $opt_batch_mode = yes ] && return
+ [ "x$opt_batch_mode" = xyes ] && return
ncolumns=`misc_get_console_column_size`
- if [ $# -eq 0 ]
- then
- fold -s -w $ncolumns <&3
- else
- fold -s -w $ncolumns "$@"
- fi
+ fold -s -w $ncolumns "$@"
}
# ============= Output a credit =============
message_credit ()
{
local ncolumns
- [ $opt_batch_mode = yes ] && return
+ [ "x$opt_batch_mode" = xyes ] && return
ncolumns=`misc_get_console_column_size`
message_version | fold -s -w $ncolumns
fold -s -w $ncolumns << eof
-- Ports upgrading utility for massive forced reinstallation
-- And for those who are pursuing the perfect packages environment
-Copyright (C) 2010 - 2013 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
+Copyright (C) 2010 - 2015 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
Email: <sakaue.mamoru@samurai.mwghennn.net>
Homepage: <http://www.mwghennndo.com/software/portsreinstall/>
eof
message_opening_notice ()
{
local ncolumns
- [ $opt_batch_mode = yes ] && return
+ [ "x$opt_batch_mode" = xyes ] && return
ncolumns=`misc_get_console_column_size`
fold -s -w $ncolumns << eof
# ============= Output the relation of the current port with specified targets =============
message_target_relations ()
{
- [ $opt_batch_mode = yes ] && return
+ [ "x$opt_batch_mode" = xyes ] && return
( set -e
origin=$1
database_query_get_target_attributes it "$origin"