count chars, not bytes

pull/14/head
chris west 4 years ago
parent 85998aba06
commit 6a429c8a86

@ -111,12 +111,11 @@ To enable just TLS support, or just Tor support, use `--features`:
## todo ## todo
- [ ] don't create new strings for every Line
- [ ] catch SIGWINCH - [ ] catch SIGWINCH
- [ ] disable ctrl-c outside of raw mode (telnet)
## bugs ## bugs
- [ ] ctrl-c while telneting kills phetch
- [ ] unknown keypress: [ during status messages - [ ] unknown keypress: [ during status messages
- [ ] new status doesn't replace old (download complete -> copy url) - [ ] new status doesn't replace old (download complete -> copy url)

@ -75,7 +75,7 @@ impl Line {
/// Returns the text field of this line, given a raw Gopher response. /// Returns the text field of this line, given a raw Gopher response.
/// The same Line must always be used with the same Gopher response. /// The same Line must always be used with the same Gopher response.
pub fn text<'a>(&self, raw: &'a str) -> &'a str { pub fn text<'a>(&self, raw: &'a str) -> &'a str {
if raw.len() >= self.text_end && self.start < self.text_end { if self.start < self.text_end {
&raw[self.start + 1..self.text_end] &raw[self.start + 1..self.text_end]
} else { } else {
"" ""
@ -820,7 +820,7 @@ impl Menu {
let s = self let s = self
.input .input
.chars() .chars()
.take(self.input.len()) .take(self.input.chars().count())
.collect::<String>(); .collect::<String>();
if let Ok(num) = s.parse::<usize>() { if let Ok(num) = s.parse::<usize>() {
if num > 0 && num <= self.links.len() { if num > 0 && num <= self.links.len() {
@ -896,7 +896,7 @@ pub fn parse_line(start: usize, raw: &str) -> Option<Line> {
} }
let line = &raw[start..]; let line = &raw[start..];
let end = line.find('\n').unwrap_or_else(|| line.len()) + start; let end = line.find('\n').unwrap_or_else(|| line.chars().count()) + start;
let line = &raw[start..end]; // constrain \t search let line = &raw[start..end]; // constrain \t search
let text_end = if let Some(i) = line.find('\t') { let text_end = if let Some(i) = line.find('\t') {
i + start i + start

@ -166,8 +166,9 @@ impl Text {
let mut longest = 0; let mut longest = 0;
for line in response.split_terminator('\n') { for line in response.split_terminator('\n') {
lines += 1; lines += 1;
if line.len() > longest { let count = line.chars().count();
longest = line.len(); if count > longest {
longest = count;
} }
} }

Loading…
Cancel
Save