我正在处理我的bash项目和
我希望只要终端以任何分辨率执行脚本,标题ascii art就会在中心自动调整。配偶是否可能? 以下是我的代码:
internal class DF : IEditorDataFilter
{
public object Convert(EditorDataFilterConvertArgs conversionArgs)
{
switch(conversionArgs.Direction)
{
case ConversionDirection.DisplayToEditor:
break;
case ConversionDirection.EditorToDisplay:
var valueAsString = conversionArgs.Value.ToString();
var year = int.Parse(valueAsString.Substring(0, 4));
var month = int.Parse(valueAsString.Substring(4, 2));
var day = int.Parse(valueAsString.Substring(6, 2));
var hours = int.Parse(valueAsString.Substring(8, 2));
var minutes = int.Parse(valueAsString.Substring(10, 2));
var result = new DateTime(year, month, day, hours, minutes, 0).ToString("yyyy-MM-dd HH:mm:ss");
conversionArgs.Handled = true;
conversionArgs.IsValid = true;
return result;
case ConversionDirection.OwnerToEditor:
break;
case ConversionDirection.EditorToOwner:
break;
default:
break;
}
return conversionArgs.Value;
}
}
答案 0 :(得分:2)
您可以使用返回终端宽度的COLUMNS环境变量。
banner_width=46
indent=$(( (COLUMNS - banner_width) / 2 ))
prefix=''
for ((i=1; i<=indent; i++)) ; do
prefix+=' '
done
echo
echo -e "${prefix}1▄██████▄#0000▄████████0000▄████████11▄██████▄ ";