Giter VIP home page Giter VIP logo

Comments (10)

phsym avatar phsym commented on May 24, 2024

Hi @sphinxc0re
First, you are not adding item_cell to the table, but item.name instead.
But even doing this won't be enough to display the colour correctly. In fact, you should not use the row! macro to create a new row from cells, since the macro will call to_string() on the cell in order to create a new cell. The macros are use to create tables/rows/cells from elements which can be converted to strings. Maybe I should consider refactoring this.
Heres what you should fo instead :

for .. in .. {
    let mut index_cell = Cell::from(&index);
    index_cell.align(Alignment::RIGHT);

    let mut item_cell = Cell::from(&item.name);
    item_cell.style(Attr::ForegroundColor(0x00AAFF));
    table.add_row(Row::new(vec![index_cell, item_cell, cell!(amount)]));
}

from prettytable-rs.

phsym avatar phsym commented on May 24, 2024

By the way, I'm not 100% sure you can use 0x00AAFF as a foreground color. Sorry I can't check this right now.
This depends on the term crate and the colors should be one of those.

from prettytable-rs.

sphinxc0re avatar sphinxc0re commented on May 24, 2024

Thank you for your fast response @phsym
I will try to refactor it as shown above

from prettytable-rs.

phsym avatar phsym commented on May 24, 2024

you're welcome

from prettytable-rs.

phsym avatar phsym commented on May 24, 2024

@sphinxc0re any update ?

from prettytable-rs.

sphinxc0re avatar sphinxc0re commented on May 24, 2024

@phsym I removed the dependency from my project entirely but only to make it a crate. When I write the first implementation, I'll definitely reconsider using prettytable-rs

from prettytable-rs.

phsym avatar phsym commented on May 24, 2024

I'm closing issue for now. Feel free to reopen it later

from prettytable-rs.

m4b avatar m4b commented on May 24, 2024

So i'm not sure the best solution here, I noticed that the style spec isn't showing up for name_cell below, and I believe it's due to what you said above about to_string being called.

what would be the best way to mix and match style strings in the case below?

            let ph_name_table = |phdr: &elf::ProgramHeader| {
                let typ = phdr.p_type;
                let name = program_header::pt_to_str(typ);
                match typ {
                    program_header::PT_LOAD    => Cell::new(name).style_spec("Fr"),
                    program_header::PT_INTERP  => Cell::new(name).style_spec("Fy"),
                    program_header::PT_DYNAMIC => Cell::new(name).style_spec("Fc"),
                    _ =>  Cell::new(name),
                }
            };
            for (i, phdr) in phdrs.into_iter().enumerate() {
                let name_cell = ph_name_table(&phdr);
                let flags = ph_flag(&phdr);
                table.add_row(row![
                    format!("{} ", i),
                    name_cell,
                    format!("{:>4} ", flags),
                    Fy->format!("{:<#x} ", phdr.p_offset),
                    Fr->format!("{:<#x} ", phdr.p_vaddr),
                    bFr->format!("{:<#x} ", phdr.p_paddr),
                    Fg->format!("{:<#x} ", phdr.p_filesz),
                    bFg->format!("{:<#x} ", phdr.p_memsz),
                    format!("{:#x}", phdr.p_align)
                ]);
            }
            table.print_tty(self.opt.color);

from prettytable-rs.

phsym avatar phsym commented on May 24, 2024

Well, I would write

table.add_row(Row::new(vec![
                    cell!(format!("{} ", i)),
                    name_cell,
                    cell!(format!("{:>4} ", flags)),
                    cell!(Fy->format!("{:<#x} ", phdr.p_offset)),
                    cell!(Fr->format!("{:<#x} ", phdr.p_vaddr)),
                    cell!(bFr->format!("{:<#x} ", phdr.p_paddr)),
                    cell!(Fg->format!("{:<#x} ", phdr.p_filesz)),
                    cell!(bFg->format!("{:<#x} ", phdr.p_memsz)),
                    cell!(format!("{:#x}", phdr.p_align))
                ]));

I'm agree this could probably made better by adding other macros and / or refactoring the existing ones.

from prettytable-rs.

phsym avatar phsym commented on May 24, 2024

Maybe

cell!(Fy->format!("{:<#x} ", phdr.p_offset))

could be made into

format_cell!("Fy", "{:<#x} ", phdr.p_offset)

or maybe we could refacor the cell! macro so that

cell!(Fg -> "foobar")

could be written

cell!("Fg":"foobar")

(But need to find another symbol than :)
Then you could store the style string into a variable and pass it later during table contruction

from prettytable-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.