summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2015-05-03 16:19:58 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2015-05-03 16:20:06 +0200
commitb421a17ed14e966bddb62165c9d944e565f1ba7a (patch)
treec6e08f62357b58d1338a4515d3754b70243d5ebb
parent383bbe27eb0e64f06ea563113c2d1ebf56c3b7d8 (diff)
downloadvtcol-b421a17ed14e966bddb62165c9d944e565f1ba7a.tar.gz
vtcol.rs: parse color indices in scheme files
-rw-r--r--vtcol.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/vtcol.rs b/vtcol.rs
index 0b86fc2..14abf4b 100644
--- a/vtcol.rs
+++ b/vtcol.rs
@@ -402,12 +402,22 @@ impl Palette {
while let Ok(line) = reader.read_line() {
let len = line.len();
if len < 8_us { panic!("invalid line in string: {}", line); };
- if let Some(idx) = line.find_str("#") {
- let idx = idx + 1_us;
- if idx > len - 6_us { /* no room left for color definition after '#' char */
+ if let Some(off) = line.find_str("#") {
+ if off != 0_us {
+ /* Palette index specified, number prepended */
+ let str_idx = line.slice_chars(0, off);
+ let parse_res : Option<usize>
+ = std::str::FromStr::from_str(str_idx);
+ match parse_res {
+ Some(new_idx) => pal_idx = new_idx * 3_us,
+ None => ()
+ }
+ }
+ let off = off + 1_us;
+ if off > len - 6_us { /* no room left for color definition after '#' char */
panic!("invalid color definition: {}", line);
}
- let col = line.slice_chars(idx, idx + RAW_COLEXPR_SIZE);
+ let col = line.slice_chars(off, off + RAW_COLEXPR_SIZE);
let (r, g, b) = rgb_of_hex_triplet(col);
pal[pal_idx + 0_us] = r;