How did NPM create the border for their update message? - unicode

I'm assuming they used unicode characters to render the yellow box around the update message.
What characters were used and does it look the same on all platforms?

How did NPM create the border for their update message?
NPM uses npmlog to print to the console, and npmlog utilizes console-control-strings & gauge.
console-control-strings mostly offers convenience functions for moving the cursor around the line and coloring the text.
gauge provides the progress bar and spinner and a way to style them.
What characters were used and does it look the same on all platforms?
Unicode box-drawing characters are used for the border characters. I didn't research the exact unicode characters that NPM uses. Assuming that the terminal/platform is implemented to support unicode and, doesn't override the standard charset with its own characters (ie. emojis), I don't see why it wouldn't look the same across platform.
The below snippet unicode characters don't match exactly. Instead, it demonstrates how to use control-control-strings to print something close to what NPM outputs. I'm sure with enough tinkering you could get it to be exact.
const control = require('console-control-strings')
let title = `${control.color('cyan')}Update available 5.0.3 \u2192 5.0.4${control.color('reset')}`
let subtitle = `Run ${control.color('cyan')} npm i -g npm ${control.color('reset')}`
let borderWidth = (title.length > subtitle.length ? title.length : subtitle.length)
let topLeftCorner = '\u256D'
let topRightCorner = '\u256E'
let btmRightCorner = '\u256F'
let btmLeftCorner = '\u2570'
let border = [...Array(borderWidth)].map(() => { return '\u2500' }).join('')
let topBorder = `${control.nextLine()}${control.color('yellow')}${topLeftCorner}${border}${topRightCorner}${control.color('reset')}`
let btmBorder = `${control.nextLine()}${control.color('yellow')}${btmLeftCorner}${border}${btmRightCorner}${control.color('reset')}`
let lineWrapper = `${control.color('yellow')}\u2502${control.color('reset')}`
console.log(topBorder)
console.log(`${lineWrapper}${control.forward(borderWidth)}${lineWrapper}`)
console.log(`${control.nextLine()}${lineWrapper}${control.forward(4)}${title}${control.forward(5)}${lineWrapper}`)
console.log(`${lineWrapper}${control.forward(11)}${subtitle}${control.forward(10)}${lineWrapper}`)
console.log(`${lineWrapper}${control.forward(borderWidth)}${lineWrapper}`)
console.log(`${btmBorder}${control.color('reset')}`)

Related

How can I get text value of TMPro Text without markup tags in Unity?

I am trying to get text value in TMPro Text component without markup tags but haven't found any solutions.
Say, <b><color=red>Hello </color><b> world is the value in TMPro Text, and I just want Hello world in c# script.
Bear in mind that tag <b> and color will change, so I would love to remove tags dynamically, meaning I would like not to replacing each tag by text.replace("<b>", "") kind of things.
Does anyone know how to do it?
I dont know about the option of using HTML on tmp but you can attach the text to your script by create a new variable like that:
[SerializeField] TMP_Text textVar;
then you can drag you tmp game object to the component that include this script
and the you can change the text like that:
textVar.text = "what ever";
or get text like that:
string textString = textVar.text;
for the color you can use
Color color = textVar.color;
You can use TMP_Text.GetParsedText () to get the text after it has been parsed and rich text tags removed.
Alternatively you can also use regular expressions to search a string for rich text tags, and remove them while preserving the rest of the string.
using System.Text.RegularExpressions;
public static string GetString (string str)
{
Regex rich = new Regex (#"<[^>]*>");
if (rich.IsMatch (str))
{
str = rich.Replace (str, string.Empty);
}
return str;
}

Flutter/Dart programmatically unicode string

I have a list of customized icons to my app, it comes like below setted as IconData, note codePoint (0xe931).
IconData angry_face = IconData(0xe931, fontFamily: _fontFamily);
There's nothing wrong with that, but I've some cases where I need this icon as Unicode string to be used as a text. It should be done just like:
// It works too
Text('\ue931', style: TextStyle(fontFamily: _fontFamily));
The problem is:
I don't wanna use this code "by hand" because this icons are changed constantly by designers team and sometimes it changes its code messing up my app icons. What I need to do is get the icon object and parse it to the Unicode string, so I can use it with a Text widget.
I thought that would work to get programmatically that code and just use it, but it don't:
var iconcode = iconData.codePoint.toRadixString(16);
var result;
// Error: An escape sequence starting with '\u'
// must be followed by 4 hexadecimal digits or
// from 1 to 6 digits between '{' and '}'
result = '\u$iconcode';
// Just a simple string
result = '\\u$iconcode';
In few words: How can I parse programmatically int codePoint to a valid Unicode string?
Here's the right answer. I tried everything but this... Thank you #julemand101
final result = String.fromCharCode(iconData.codePoint);

Cocoa/Swift: NSStatusBarItem's text gets trimmed when using a picture

When creating an NSStatusBar.systemStatusBar related application for MacOS, I stumbled upon a problem that seemed strange to begin with. The problem is: when using an image and a text for the NSStatusBar, the text was being clipped unless you manually specified a sufficient length, which would be hardcoded and causes problems with alternating lengths. How can this be solved?
// The -1 is supposed to mean "variable length"
let myStatusItem = NSStatusBar.systemStatusBar().statusItemWithLength(CGFloat(-1))
myStatusItem.image = NSImage(named: "customImage")
myStatusItem.title = "Some special information"
This would be the normal case where this problem will occur.
After playing around with some ridiculous variations, I realized that the problem can be fixed when using BOTH .title and .attributedTitle parameters of the NSStatusBar item.
Also make sure that you declare the .image BEFORE you declare the titles. If you want to use the .attributedTitle, define it after .title - if you want to use the plain .title, just define it after the .attributedTitle.
// The -1 is supposed to mean "variable length"
let myStatusItem = NSStatusBar.systemStatusBar().statusItemWithLength(CGFloat(-1))
myStatusItem.image = NSImage(named: "customImage")
myStatusItem.title = "Some special information"
myStatusItem.attributedTitle = NSAttributedString(string: "Some special information")

iText support for HIndi and Arabic

Our project needs dynamic PDF generation in 6 languages which consists of Hindi and Arabic. iText works brilliantly for other languages except these two. Can someone let me know if current version of iText(5.5.5) have ligature implementation for Hindi and Arabic?
about Arabic language:
I understand you face one of two problems:
the Arabic words don't appear.
the Arabic words appears like :
the solution is:
first: update your itext 5.5.8 to itext 7 implementation:
https://search.maven.org/artifact/com.itextpdf/itext7-core/7.2.2/pom
then edit your code:
String font = "your Arabic font";
PdfFontFactory.register(font);
FontProgram fontProgram = FontProgramFactory.createFont(font, true);
PdfFont f = PdfFontFactory.createFont(fontProgram, PdfEncodings.IDENTITY_H);
LanguageProcessor languageProcessor = new ArabicLigaturizer();
com.itextpdf.kernel.pdf.PdfDocument tempPdfDoc = new
com.itextpdf.kernel.pdf.PdfDocument(new PdfReader(pdfFile.getPath()), TempWriter);
com.itextpdf.layout.Document TempDoc = new
com.itextpdf.layout.Document(tempPdfDoc);
com.itextpdf.layout.element.Paragraph paragraph0 = new
com.itextpdf.layout.element.Paragraph(languageProcessor.process("الاستماره الالكترونية"))
.setFont(f).setBaseDirection(BaseDirection.RIGHT_TO_LEFT)
.setFontSize(15);
//and look how i useded setBaseDirection & and don't use TextAlignment ,it will work without it

3DText - Change Text Through Script - Unity

I have read lot of questions on how to change text of a 3DText from script.
Lot of them suggested the following :::
GetComponent(TextMesh).text = "blah";
But when I try to use this, I get an error Expression denotes atype', where a variable',value' or method group' was expected
I tried a lot of examples and couldn't really get it to work.
TextMesh textMesh;
textMesh = (TextMesh) descriptionObject.transform.GetComponent("Text Mesh");
textMesh.text = "Name : ABC";
The above code though Compiles without errors doesn't change the text. Can someone help me out with this? How do I change the TEXT of a 3DText Object.
Thanks...
This would be a prettier solution than one already given(C# script used in example) :
//define a Textmesh that we want to edit
public TextMesh tm;
// here in start method (run at instantiating of script) i find component of type
// TextMesh ( <TextMesh> ) of object named"nameOfTheObject" and reference it
// via tm variable;
void Start () {
tm = (TextMesh)GameObject.Find ("nameOfTheObject").GetComponent<TextMesh>();
// here we change the value of displayed text
tm.text = "new Text u want to see";
}
Or if u want to do it the shortest way possible (syntax wise):
//keep in mind this requires for the script to be attached to the object u
// are editing (the 3dText);
//same as above, the only difference is the note in the line above as this
// method is run from gameObject.GetComponent....
// gameObject is a variable which would be equivalent of this.GetComp...
// in some other programming languages
GetComponent<TextMesh>().text ="new Text u want";
This Works !!!!
textMesh = (TextMesh) descriptionObject.transform.GetComponent(typeof(TextMesh));
textMesh.text = "Name : ABC";