fixed some minor issue with left margin calculation

This commit is contained in:
vishalxl 2022-08-18 18:58:14 +05:30
parent 148527c7d6
commit 52b52cfe05
2 changed files with 20 additions and 20 deletions

View File

@ -45,8 +45,8 @@ usage: $exename [OPTIONS]
from a relay. If not provided, then events for default or given user are shown. Same as -q from a relay. If not provided, then events for default or given user are shown. Same as -q
--align <left> When "left" is given as option to this argument, then the text is aligned to left. By default --align <left> When "left" is given as option to this argument, then the text is aligned to left. By default
the posts or text is aligned to the center of the terminal. Same as -a the posts or text is aligned to the center of the terminal. Same as -a
--width <width as num> This specifies how wide you want the text to be, in number of columns. Default is 80. --width <width as num> This specifies how wide you want the text to be, in number of columns. Default is $gDefaultTextWidth.
Cant be less than $gMinValidScreenWidth. Same as -c Cant be less than $gMinValidTextWidth. Same as -c
--help Print this usage message and exit. Same as -h --help Print this usage message and exit. Same as -h
"""; """;
@ -124,7 +124,7 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
case 1: case 1:
// align the text again in case the window size has been changed // align the text again in case the window size has been changed
if( gAlignment == "center") { if( gAlignment == "center") {
gNumLeftMarginSpaces = (stdout.terminalColumns - 80 )~/2; gNumLeftMarginSpaces = (stdout.terminalColumns - gTextWidth )~/2;
} }
node.printTree(0, true, DateTime.now().subtract(Duration(days:numLastDays))); node.printTree(0, true, DateTime.now().subtract(Duration(days:numLastDays)));
@ -138,7 +138,7 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
break; break;
} }
stdout.write("Type initial few letters of the id of event to reply to ( leave blank if you want to make a post; type x if you want to cancel): "); stdout.write("\nType initial few letters of the id of event to\nreply to (leave blank if you want to make a\nnew post; type x if you want to cancel): ");
String? $replyToVar = stdin.readLineSync(); String? $replyToVar = stdin.readLineSync();
String replyToId = $replyToVar??""; String replyToId = $replyToVar??"";
if( replyToId == "x") { if( replyToId == "x") {
@ -197,17 +197,17 @@ Future<void> main(List<String> arguments) async {
} }
if( argResults[widthArg] != null) { if( argResults[widthArg] != null) {
int tempScreenWidth = int.parse(argResults[widthArg]); int tempTextWidth = int.parse(argResults[widthArg]);
if( tempScreenWidth < gMinValidScreenWidth ) { if( tempTextWidth < gMinValidTextWidth ) {
print("Screen-width cannot be less than $gMinValidScreenWidth. Going to use the defalt value of $screenWidth"); print("Text-width cannot be less than $gMinValidTextWidth. Going to use the defalt value of $gTextWidth");
} else { } else {
print("Going to use $screenWidth columns for text on screen."); print("Going to use $gTextWidth columns for text on screen.");
screenWidth = tempScreenWidth; gTextWidth = tempTextWidth;
} }
} }
// can be computed only after screenWidth has been found // can be computed only after screenWidth has been found
gNumLeftMarginSpaces = (stdout.terminalColumns - 80 )~/2; gNumLeftMarginSpaces = (stdout.terminalColumns - gTextWidth )~/2;
// undo above if left option is given // undo above if left option is given
if( argResults[alignArg] != null) { if( argResults[alignArg] != null) {
@ -267,7 +267,7 @@ Future<void> main(List<String> arguments) async {
contactList = getContactFeed(getRecievedEvents()[latestContactIndex].eventData.contactList, 300); contactList = getContactFeed(getRecievedEvents()[latestContactIndex].eventData.contactList, 300);
} }
stdout.write('waiting for feed to come in...............'); stdout.write('Waiting for feed to come in...............');
Future.delayed(const Duration(milliseconds: numWaitSeconds * 1), () { Future.delayed(const Duration(milliseconds: numWaitSeconds * 1), () {
// count feed events // count feed events

View File

@ -2,10 +2,10 @@ import 'dart:io';
import 'dart:convert'; import 'dart:convert';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
const int gMinValidScreenWidth = 60; const int gMinValidTextWidth = 60;
const int defaultScreenWidth = 80; const int gDefaultTextWidth = 120;
int screenWidth = defaultScreenWidth; int gTextWidth = gDefaultTextWidth;
const int spacesPerDepth = 8; const int gSpacesPerDepth = 8;
int gNumLeftMarginSpaces = 0; // this number is modified in main int gNumLeftMarginSpaces = 0; // this number is modified in main
String gAlignment = "center"; // is modified in main if --align argument is given String gAlignment = "center"; // is modified in main if --align argument is given
@ -32,7 +32,7 @@ List<String> gBots = [ "3b57518d02e6acfd5eb7198530b2e351e5a52278fb2499d14b66db2
int gDebug = 0; int gDebug = 0;
void printDepth(int d) { void printDepth(int d) {
for( int i = 0; i < spacesPerDepth * d + gNumLeftMarginSpaces; i++) { for( int i = 0; i < gSpacesPerDepth * d + gNumLeftMarginSpaces; i++) {
stdout.write(" "); stdout.write(" ");
} }
} }
@ -65,7 +65,7 @@ String rightShiftContent(String s, int numSpaces) {
newString += spacesString; newString += spacesString;
newlineCounter = 0; newlineCounter = 0;
} else { } else {
if( newlineCounter >= (screenWidth - numSpaces)) { if( newlineCounter >= (gTextWidth - numSpaces)) {
newString += "\n"; newString += "\n";
newString += spacesString; newString += spacesString;
newlineCounter = 0; newlineCounter = 0;
@ -215,7 +215,7 @@ class EventData {
} }
content = expandMentions(content); content = expandMentions(content);
String contentShifted = rightShiftContent(content, spacesPerDepth * depth + 10); String contentShifted = rightShiftContent(content, gSpacesPerDepth * depth + 10);
printDepth(depth); printDepth(depth);
stdout.write("+-------+\n"); stdout.write("+-------+\n");