MCPcopy Index your code
hub / github.com/clearloop/leetcode-cli / fmt

Method fmt

src/cache/models.rs:62–147  ·  view source on GitHub ↗
(&self, f: &mut std::fmt::Formatter<'_>)

Source from the content-addressed store, hash-verified

60static SPACE: &str = " ";
61impl std::fmt::Display for Problem {
62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 let space_2 = SPACE.repeat(2);
64 let mut lock = space_2.as_str();
65 let mut done = space_2.normal();
66 let mut id = "".to_string();
67 let mut name = "".to_string();
68 let mut level = "".normal();
69
70 if self.locked {
71 lock = LOCK
72 };
73 if self.status == "ac" {
74 done = DONE.green().bold();
75 } else if self.status == "notac" {
76 done = NDONE.green().bold();
77 }
78
79 match self.fid.to_string().len() {
80 1 => {
81 id.push_str(&SPACE.repeat(2));
82 id.push_str(&self.fid.to_string());
83 id.push_str(SPACE);
84 }
85 2 => {
86 id.push_str(SPACE);
87 id.push_str(&self.fid.to_string());
88 id.push_str(SPACE);
89 }
90 3 => {
91 id.push_str(SPACE);
92 id.push_str(&self.fid.to_string());
93 }
94 4 => {
95 id.push_str(&self.fid.to_string());
96 }
97 _ => {
98 id.push_str(&space_2);
99 id.push_str(&space_2);
100 }
101 }
102
103 let name_width = UnicodeWidthStr::width(self.name.as_str());
104 let target_width = 60;
105 if name_width <= target_width {
106 name.push_str(&self.name);
107 name.push_str(&SPACE.repeat(target_width - name_width));
108 } else {
109 // truncate carefully to target width - 3 (because "..." will take some width)
110 let mut truncated = String::new();
111 let mut current_width = 0;
112 for c in self.name.chars() {
113 let char_width = UnicodeWidthChar::width(c).unwrap_or(0);
114 if current_width + char_width > target_width - 3 {
115 break;
116 }
117 truncated.push(c);
118 current_width += char_width;
119 }

Callers

nothing calls this directly

Calls 1

update_after_acMethod · 0.80

Tested by

no test coverage detected