jcubic / jquery.terminal

jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
https://terminal.jcubic.pl
MIT License
3.12k stars 569 forks source link

How to change number of characters? #215

Closed sumy7 closed 8 years ago

sumy7 commented 8 years ago

Hello. I have try jquery.terminal today. It's cool. But I ran into a problem. I resize the term to 426px width, but only got 35 characters per line. It's the half of one line. I found that the number of characters relative to num_rows.

I want to fill up the whole line. Is there any way or trick to solve this problem? sorry for my English.

jcubic commented 8 years ago

You should have about 55 characters. Do you have a demo where this is happening, where I can try things out? Maybe jsfiddle?

sumy7 commented 8 years ago

I copy my code to jsfiddle. http://jsfiddle.net/sumy/f7qdrp1y/

jcubic commented 8 years ago

You need to set the same font on .terminal because it's used for character calculation:

.terminal {
  font-family: fantasquesansmono;
}

You will have 67 characters http://jsfiddle.net/f7qdrp1y/3/

sumy7 commented 8 years ago

Thanks a lot. I add the css, and clear browser cache, then it works.

sumy7 commented 8 years ago

Thanks for your suggestion. I try this method in my blog, but it didn't work. /(ㄒoㄒ)/~~

You notice that the problem is cause by font-family, I want to say what I understand. In the function char_size() function, a fake terminal created calcualte the dimention of &nbsp; representing one character. the normal <span> width is 6, but my is 12. font-family from jquery.terminal.css is

.terminal, .cmd {
    font-family: FreeMono, monospace;
}

I don't have FreeMono and monospace in my computer. so a default font which have a big &nbsp; would be selected. My solution is using a higher priority selector to make my font-family be selected.

.terminal span{
    font-family: fantasquesansmono !important;
}
jcubic commented 8 years ago

monospace is meta name same as sans or sans-serif, browser will pick the font of that type.