summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hbar.c12
-rwxr-xr-xtest/hbar.sh9
2 files changed, 10 insertions, 11 deletions
diff --git a/src/hbar.c b/src/hbar.c
index c0272b9..59cf888 100644
--- a/src/hbar.c
+++ b/src/hbar.c
@@ -38,11 +38,9 @@ void human_format(int bytes, char *output) {
size_t len(char *s) {
size_t len = 0;
- for (; *s; s++) {
- if ((*s & 0XC0) != 0x80) {
+ for (; *s; s++)
+ if ((*s & 0XC0) != 0x80)
len++;
- }
- }
return len;
}
@@ -50,17 +48,17 @@ void printat(char *s, size_t index) {
index++;
for (; *s; s++) {
if ((*s & 0XC0) != 0x80) {
+ if (index <= 0)
+ return;
index--;
}
if (index <= 0) {
fwrite(s, 1, 1, stdout);
- if ((*s & 0XC0) == 0x80)
- return;
}
}
}
-int main (int argc, char **argv) {
+int main(int argc, char **argv) {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
int width = w.ws_col;
diff --git a/test/hbar.sh b/test/hbar.sh
index 8d47595..71713ef 100755
--- a/test/hbar.sh
+++ b/test/hbar.sh
@@ -1,17 +1,18 @@
#!/bin/sh
HBAR=./bin/hbar
-#TEXT="Hello there"
-TEXT="Привет мир"
UNIT="mb"
MAX=100
+TEXT="✓ Привет World Привет World Привет World Привет World Привет World Привет World "
for x in $(seq $MAX); do
${HBAR} -T "${TEXT}" -u ${UNIT} $x $MAX
- read
+ sleep 0.01
done
-${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX
+TEXT="Hello there"
+
+${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX
for x in $(seq $MAX); do
${HBAR} -T "${TEXT}" -u ${UNIT} $x $MAX
sleep 0.01