+#endif /* X11 */
+
+static void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_size, double usage)
+{
+ struct bar *b = obj->special_data;
+ int width, i, scaledusage;
+
+ if (!b)
+ return;
+
+ width = b->width;
+ if (!width)
+ width = DEFAULT_BAR_WIDTH_NO_X;
+
+ if (width > buf_max_size)
+ width = buf_max_size;
+
+ scaledusage = round_to_int( usage * width / 255);
+
+ for (i = 0; i < scaledusage; i++)
+ buffer[i] = '#';
+
+ for (; i < width; i++)
+ buffer[i] = '_';
+
+ buffer[i] = 0;
+}
+
+#ifdef X11
+static void new_bar_in_x11(struct text_object *obj, char *buf, int usage)
+{
+ struct special_t *s = 0;
+ struct bar *b = obj->special_data;
+
+ s = new_special(buf, BAR);
+
+ s->arg = usage;
+ s->width = b ? b->width : default_bar_width;
+ s->height = b ? b->height : default_bar_height;
+}
+#endif /* X11 */
+
+/* usage is in range [0,255] */
+void new_bar(struct text_object *obj, char *p, int p_max_size, int usage)
+{
+ if (!p_max_size)
+ return;
+
+ usage = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
+
+#ifdef X11
+ if ((output_methods & TO_X))
+ new_bar_in_x11(obj, p, usage);
+ else
+#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, usage);
+}