[Question]
  [
The code should take a string as input from keyboard:
```
The definition of insanity is quoting the same phrase again and again and not expect despair.
```
The output should be like this(not sorted in any particular order): 
```
  :  15
. :  1
T :  1
a :  10
c :  1
e :  8
d :  4
g :  3
f :  2
i :  10
h :  3
m :  1
o :  4
n :  10
q :  1
p :  3
s :  5
r :  2
u :  1
t :  6
y :  1
x :  1
```
All ASCII characters count unicode is not a requirement, spaces, quotes,etc and input should come from keyboard / not constants, attributes, output should be printed with new line after each character like in the above example, it should not be returned as string or dumped as hashmap/dictionary etc, so `x : 1` and `x: 1` are ok, but `{'x':1,...` and `x:1` are not. 
Q: Function or complete program taking stdin and writing stdout?  
A: Code needs to be a program taking input using standard in and display the result via standard out.
# Scoreboard:
[Shortest overall](https://codegolf.stackexchange.com/a/157214/12328): 5 bytes
~~[Shortest overall](https://codegolf.stackexchange.com/questions/19068/display-number-of-occurrences-for-every-character-in-an-input-string#answer-19104): 7 bytes~~
  
[Answer]
## PHP - 68 (or 39) bytes
```
<?foreach(count_chars(fgets(STDIN),1)as$k=>$v)echo chr($k)." : $v
";
```
Output for the example text:
```
  : 15
. : 1
T : 1
a : 10
c : 1
d : 4
e : 8
f : 2
g : 3
h : 3
i : 10
m : 1
n : 10
o : 4
p : 3
q : 1
r : 2
s : 5
t : 6
u : 1
x : 1
y : 1
```
If the exact output is not required, this would work for **39 bytes**:
```
<?print_r(count_chars(fgets(STDIN),1));
```
Sample output:
```
Array
(
    [32] => 15
    [46] => 1
    [84] => 1
    [97] => 10
    [99] => 1
    [100] => 4
    [101] => 8
    [102] => 2
    [103] => 3
    [104] => 3
    [105] => 10
    [109] => 1
    [110] => 10
    [111] => 4
    [112] => 3
    [113] => 1
    [114] => 2
    [115] => 5
    [116] => 6
    [117] => 1
    [120] => 1
    [121] => 1
)
```
where each numerical index refers the ordinal value of the character it represents.
I suspect very strongly that using an in-built function that does exactly what the problem states will soon be disallowed.
[Answer]
# k (~~8~~ 7)
```
#:'=0:0
```
Example
```
k)#:'=:0:0
The definition of insanity is quoting the same phrase again and again and not expect despair.
T| 1
h| 3
e| 8
 | 15
d| 4
f| 2
i| 10
n| 10
t| 6
o| 4
s| 5
a| 10
y| 1
q| 1
u| 1
g| 3
m| 1
p| 3
r| 2
x| 1
c| 1
.| 1
```
edit: Down to seven, H/T Aaron Davies
## Explanation
Take a String from keyboard :
```
k)0:0
text
"text"
```
Group the distinct elements and return a map containing key as distinct characters and values are the indices where the distinct elements occur.
```
k)=0:0
text
t| 0 3
e| ,1
x| ,2
```
Now count values of each entry in the map.
```
k)#:'=0:0
text
t| 2
e| 1
x| 1
```
[Answer]
# GNU core utils - 29 22 20 chars (53 with formatting)
Wumpus's improvement (20 chars):
```
fold -1|sort|uniq -c
```
Firefly's improvement (22 chars):
```
grep -o .|sort|uniq -c
```
joeytwiddle's original (29 chars):
```
sed 's+.+\0\n+g'|sort|uniq -c
```
Originally I used `sed` to simply add a newline after each character. Firefly improved on that with `grep -o .`, since `-o` displays every matched pattern on its own line. Wumpus pointed out a further improvement using `fold -1` instead. Nice work!
`uniq` does the real work, although it only applies to sorted lists.
Note that the output format does not exactly match the example in the question. That requires a final run through `sed` to swap the arguments. (Waiting on an answer to Jan Dvorak's question to see if this is required...)
Reformatting with sed is "only" another 33 characters! (**Total 53**)
```
|sed 's/ *\(.*\) \(.\)/\2 :  \1/'
```
Awk can *almost* do the job whilst adding only 25 chars, but it hides the first space. Silly awk!
```
|awk '{print $2" :  "$1}'
```
I wonder if improvements can be made in the reformatting stage...
[Answer]
## Perl 6: 21 chars
```
.say for get.comb.Bag
```
```
(REPL)
> .say for get.comb.Bag
The definition of insanity is quoting the same phrase again and again and not expect despair.
"T" => 1
"h" => 3
"e" => 8
" " => 15
"d" => 4
"f" => 2
"i" => 10
"n" => 10
"t" => 6
"o" => 4
"s" => 5
"a" => 10
"y" => 1
"q" => 1
"u" => 1
"g" => 3
"m" => 1
"p" => 3
"r" => 2
"x" => 1
"c" => 1
"." => 1
```
[Answer]
# Ruby 1.9.3: 53 characters
(Based on @shiva's and @daneiro's comments.)
```
gets.split("").uniq.map{|x|puts x+" : #{$_.count x}"}
```
Sample run:
```
bash-4.1$ ruby -e 'a=gets;a.split("").uniq.map{|x|puts"#{x} : #{a.count x}"}' <<< 'Hello world'
H : 1
e : 1
l : 3
o : 2
  : 1
w : 1
r : 1
d : 1
 : 1
```
## Ruby: 44 characters
Not respecting the output format:
```
s=Hash.new 0;gets.chars{|c|s[c]+=1};pp s
```
Sample run:
```
bash-4.1$ ruby -rpp -e 's=Hash.new 0;gets.chars{|c|s[c]+=1};pp s' <<< 'Hello, world!'
{"H"=>1,
 "e"=>1,
 "l"=>3,
 "o"=>2,
 ","=>1,
 " "=>1,
 "w"=>1,
 "r"=>1,
 "d"=>1,
 "!"=>1,
 "\n"=>1}
```
[Answer]
# Python 3: 76 characters
## 76
```
import collections as c
for x,y in c.Counter(input()).items():print(x,':',y)
```
### 44
(print same characters many times, see [Wasi](https://codegolf.stackexchange.com/questions/19068/display-number-of-occurrences-for-every-character-in-an-input-string/19113#19113)'s answer for a valid version)
```
a=input()
for x in a:print(x,':',a.count(x))
```
[Answer]
## APL (15)
```
M,⍪+⌿Z∘.=M←∪Z←⍞
```
If you really need the `:`, it's **19** (but there's others who aren't including it):
```
M,':',⍪+⌿Z∘.=M←∪Z←⍞
```
Output:
```
      M,⍪+⌿Z∘.=M←∪Z←⍞
The definition of insanity is quoting the same phrase again and again and not expect despair. 
T  1
h  3
e  8
  16
d  4
f  2
i 10
n 10
t  6
o  4
s  5
a 10
y  1
q  1
u  1
g  3
m  1
p  3
r  2
x  1
c  1
.  1
```
[Answer]
### R, 30 characters
```
table(strsplit(readline(),""))
```
Example usage:
```
> table(strsplit(readline(),""))
The definition of insanity is quoting the same phrase again and again and not expect despair.
    .  a  c  d  e  f  g  h  i  m  n  o  p  q  r  s  t  T  u  x  y 
15  1 10  1  4  8  2  3  3 10  1 10  4  3  1  2  5  6  1  1  1  1 
```
[Answer]
## Perl 5, 54 characters
```
map{$h{$_}++}split//,<>;print"$_ : $h{$_}\n"for keys%h
```
[Answer]
# JavaScript
1. **~~66~~ 53 bytes:**
```
prompt(a={}).replace(/./g,function(c){a[c]=-~a[c]}),a
```
2. **~~69~~ 56 bytes:**
```
b=prompt(a={});for(i=b.length;i--;){a[b[i]]=-~a[b[i]]};a
```
3. **~~78~~ 65 bytes:**
```
prompt().split('').reduce(function(a,b){return a[b]=-~a[b],a},{})
```
**N.B.:** In all cases deleted number of bytes refer to extra `console.log()` call which is pointless if run in the console. Big thanks to [@imma](https://codegolf.stackexchange.com/users/14870/imma) for the great catch with `-~a[b]` and `prompt(a={})`. This definitely saved some more bytes.
[Answer]
# **Python 2, correctly (58)**
```
s=raw_input()
for l in set(s):print l+" : "+str(s.count(l))
```
**Output:**
```
python count.py
The definition of insanity is quoting the same phrase again and again and not expect despair.
  : 15
. : 1
T : 1
a : 10
c : 1
e : 8
d : 4
g : 3
f : 2
i : 10
h : 3
m : 1
o : 4
n : 10
q : 1
p : 3
s : 5
r : 2
u : 1
t : 6
y : 1
x : 1
```
# **Python 2, cheetah style (41)**
```
s=input()
print {l:s.count(l) for l in s}
```
**Output:**
```
python count.py
"The definition of insanity is quoting the same phrase again and again and not expect despair."
{' ': 15, '.': 1, 'T': 1, 'a': 10, 'c': 1, 'e': 8, 'd': 4, 'g': 3, 'f': 2, 'i': 10, 'h': 3, 'm': 1, 'o': 4, 'n': 10, 'q': 1, 'p': 3, 's': 5, 'r': 2, 'u': 1, 't': 6, 'y': 1, 'x': 1}
```
[Answer]
## Mathematica, 61 bytes
```
Map[{#[[1]], Length@#} &, Gather@Characters[Input[]]] // TableForm
```
It then pops up this dialog box,
![input](https://i.stack.imgur.com/3qWwe.png)
and for the sample sentence, produces as output
![output](https://i.stack.imgur.com/zDmV5.png)
[Answer]
## python 3, 49
Stealing idea from [evuez](https://codegolf.stackexchange.com/questions/19068/display-number-of-occurrences-for-every-character-in-an-input-string/19070#19070)
```
t=input()
for i in set(t):print(i,':',t.count(i))
```
input:
```
The definition of insanity is quoting the same phrase again and again and not expect despair.
```
output:
```
  :  15
. :  1
T :  1
a :  10
c :  1
e :  8
d :  4
g :  3
f :  2
i :  10
h :  3
m :  1
o :  4
n :  10
q :  1
p :  3
s :  5
r :  2
u :  1
t :  6
y :  1
x :  1
```
[Answer]
# JavaScript (~~69~~ 68 characters):
*Expects `s` to hold the string.*
```
_={};for(x in s)_[a=s[x]]=-~_[a];for(x in _)console.log(x+': '+_[x])
```
*This follows the new rules perfectly.*
**Note:** *This presumes a clean environment, with no custom properties on any standard object prototypes.*
**Edit:** 1 character less!
## Console output:
```
T: 1
h: 3
e: 8
 : 15
d: 4
f: 2
i: 10
n: 10
t: 6
o: 4
s: 5
a: 10
y: 1
q: 1
u: 1
g: 3
m: 1
p: 3
r: 2
x: 1
c: 1
.: 1
```
---
# Old answer (44 characters):
```
r={};[].map.call(s,function(e){r[e]=-~r[e]})
```
*This was valid before the rules changed.*
`r` contains the output.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 5 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Full program body. Prompts for a string from STDIN and prints newline separated table to STDOUT. Leftmost column is the input characters, and counts are right-aligned with the largest number separated from its character by a single space.
```
,∘≢⌸⍞
```
[Try it online!](https://tio.run/##TYyxDQIxEARzqtgCgGpo4ITP/pOeO/M@JL4CHglyIgKqoB43YgwRG@2sRkt53ISZRkutLpfY1nV51Our3t71/vxODb/E1W5gBI6i4mIKixAt1GmGFBxP5qIJ3q1CB0YeJioMSiQK0vDX1Bx8zrz3flgyybT9AA "APL (Dyalog Unicode) – Try It Online")
`⍞` prompt for text input from STDIN
`⌸` create a keys' table consisting of  
 `,` the unique element followed  
 `∘` by  
 `≢` the tally of the indices of its occurrence (i.e how many times it occurs)
[Answer]
# Haskell, 93
```
import Data.List
main=getLine>>=mapM(\s->putStrLn$[head s]++" : "++show(length s)).group.sort
```
[Answer]
**PowerShell (49)**
```
[char[]](read-host)|group|%{$_.Name+":"+$_.Count}
```
[Answer]
# C# (178 220 chars)
Based on @Spongeman's comment I changed it up a bit:
```
using C=System.Console;using System.Linq;class P{static void Main()
{C.WriteLine(string.Join("\n",C.ReadLine().GroupBy(x=>x)
.OrderBy(x=>x.Key).Select(g=>g.Key+":"+g.Count())));}}
```
---
```
Line breaks added for readability, my first feeble attempt at code golf! :)
class P {static void Main(){var d=new Dictionary<char,int>();
Console.ReadLine().ToList().ForEach(x=>{ if(d.ContainsKey(x))
{d[x]++;}else{d.Add(x,1);}});Console.WriteLine(string
.Join("\n",d.Keys.Select(x=>x+":" +d[x])));}}
```
[Answer]
# [Sclipting](http://esolangs.org/wiki/Sclipting), 19 characters
```
梴要⓶銻꾠⓷❸虛變梴❶⓺減負겠⓸⓸終丟
```
## Output
```
T:1
h:3
e:8
 :15
d:4
f:2
i:10
n:10
t:6
o:4
s:5
a:10
y:1
q:1
u:1
g:3
m:1
p:3
r:2
x:1
c:1
.:1
```
If you want the spaces around the `:`, change `꾠` to `긃똠`, making it 20 characters.
## Explanation
```
Get length of input string.
梴
Stack is now [ input, length ]
While {
要
    Get first character of string and push ":"
    ⓶銻꾠
    Stack is now [ length, input, firstchar, ":" ]
    Replace all occurrences of that character with empty string
    ⓷❸虛變
    Stack is now [ length, firstchar, ":", reducedinput ]
    Get the length of that, calculate difference to previous length, push "\n"
    梴❶⓺減負겠
    Stack is now [ firstchar, ":", reducedinput, newlength, diff, "\n" ]
    Move the input string and length back up, leaving output below it
    ⓸⓸
    Stack is now [ firstchar, ":", diff, "\n", reducedinput, newlength ]
                   `------------------------'                `-------'
                   Every iteration of the               The length provides
                   While loop generates                 the While loop's
                   a bit like this                      terminating condition
} End While
終
Discard the length which is now 0
丟
```
[Answer]
# F# (66 59 49, 72 with prescribed formattting)
```
let f s=s|>Seq.countBy(id)|>Seq.iter(printfn"%A")
```
Output:
```
> f The definition of insanity is quoting the same phrase again and again and not expect despair.
(' ', 15)
('.', 1)
('T', 1)
('a', 10)
('c', 1)
('d', 4)
('e', 8)
('f', 2)
('g', 3)
('h', 3)
('i', 10)
('m', 1)
('n', 10)
('o', 4)
('p', 3)
('q', 1)
('r', 2)
('s', 5)
('t', 6)
('u', 1)
('x', 1)
('y', 1)
```
With the prescribed formatting, it becomes:
```
let f s=s|>Seq.countBy(id)|>Seq.iter(fun(a,b)->printfn"\"%c\" :  %d"a b)
```
[Answer]
# Mathematica, ~~34~~ 29 bytes
Not sure why the other Mathematica answer is so complicated... ;)
```
Grid@Tally@Characters@Input[]
```
[Answer]
# Bash (20 15 characters)
```
 ptx -S.|uniq -c
 10                                        a
  1                                        c
  4                                        d
  8                                        e
  2                                        f
  3                                        g
  3                                        h
 10                                        i
  1                                        m
 10                                        n
  4                                        o
  3                                        p
  1                                        q
  2                                        r
  5                                        s
  6                                        t
  1                                        T
  1                                        u
  1                                        x
  1                                        y
```
ASCII encoding now supported
# Bash (23 characters):
```
xxd -p -c1|sort|uniq -c
  1 0a
 15 20
  1 2e
  1 54
 10 61
  1 63
  4 64
  8 65
  2 66
  3 67
  3 68
 10 69
  1 6d
 10 6e
  4 6f
  3 70
  1 71
  2 72
  5 73
  6 74
  1 75
  1 78
  1 79
```
ASCII formatting not supported
[Answer]
# Java 8, ~~273~~ ~~253~~ ~~249~~ ~~246~~ ~~239~~ 200 bytes
```
interface I{static void main(String[]a){int m[]=new int[999],i=0;for(int c:new java.util.Scanner(System.in).nextLine().getBytes())m[c]++;for(;++i<999;)if(m[i]>0)System.out.printf("%c: %d%n",i,m[i]);}}
```
-24 bytes thanks to *@Poke*.  
-7 bytes thanks to *@OlivierGrégoire*.
**Explanation:**
[Try it here.](https://tio.run/##TY/BasNADER/RQQCuzhdcnXc9NBboTf3ZnwQazmRU2tdr5zGhHy7uy499DZiRo@ZDq/41DWXZWFRGlv0BG/3qKjs4Rq4gR5ZTKkjy6mq0d5TDvqqPgp9Q9JVnuf1jo/7og2jWU1/WK0ugd2k/OlKjyI0mnKOSr1jsU7opu8sZKw7kb7OStFY21e@zrJfTpFl/JzIheXW9BXXL3v79x8mdUNqo63ZbP0Bts1WNjverSlbPB7L8nEmaKhlYeUgENrUM2K6ZuAIX1PQtAU0pSL2BMN5xEiApzQUUJp/SoIC3QbymoBxQB7dDw)
```
interface I{                        // Class
  static void main(String[]a){      //  Mandatory main-method
    int m[]=new int[999],           //  Integer-array to count the occurrences
        i=0;                        //  Index-integer, starting at 0
    for(int c:new java.util.Scanner(System.in).nextLine().getBytes())
                                    //   Loop over the input as bytes:
      m[c]++;                       //    Increase the occurrence-counter of the char by 1
    for(;++i<999;)                  //   Loop over the array:
      if(m[i]>0)                    //    If the current character occurred at least once:
        System.out.print("%c: %d%n",//     Print with proper formatting:
         i,                         //      The character
         m[i]);}}                   //      and the occurrence-count
```
[Answer]
# JavaScript, ~~44~~ 37 bytes
```
s=>[...s].map(x=>o[x]=-~o[x],o={})&&o
```
---
## Try it
```
o.innerText=JSON.stringify((f=
s=>[...s].map(x=>o[x]=-~o[x],o={})&&o
)(i.value="The definition of insanity is quoting the same phrase again and again and not expect despair."));oninput=_=>o.innerText=JSON.stringify(f(i.value))
```
```
<input id=i><pre id=o></pre>
```
[Answer]
## Powershell, 63
```
$a=@{};[char[]](read-host)|%{$a[$_]++};$a.Keys|%{"$_ :"+$a[$_]}
```
[Answer]
## Windows Command Script - 72 Bytes
```
set/p.=
:a
set/a\%.:~,1%=\%.:~,1%+1
set.=%.:~1%
%.%goto:b
goto:a
:b
set\
```
**Outputs:**
```
\=15 (space)
\.=1
\a=10
\c=1
\d=4
\e=8
\f=2
\g=3
\h=3
\i=10
\m=1
\n=10
\o=4
\p=3
\q=1
\r=2
\s=5
\T=7
\u=1
\x=1
\y=1
```
[Answer]
## J, 23 chars
```
(~.;"0+/@|:@=)/:~1!:1]1
```
Slightly different output format (line 2 is stdin):
```
   (~.;"0+/@|:@=)/:~1!:1]1
Mississippi
┌─┬─┐
│M│1│
├─┼─┤
│i│4│
├─┼─┤
│p│2│
├─┼─┤
│s│4│
└─┴─┘
```
[Answer]
# J, 22 characters
```
(~.;"0+/@(=/~.))1!:1]1
```
Example:
```
   (~.;"0+/@(=/~.))1!:1]1
The definition of insanity is quoting the same phrase again and again and not expect despair.
+-+--+
|T|1 |
+-+--+
|h|3 |
+-+--+
|e|8 |
+-+--+
| |15|
+-+--+
|d|4 |
+-+--+
|f|2 |
+-+--+
|i|10|
+-+--+
|n|10|
+-+--+
|t|6 |
+-+--+
|o|4 |
+-+--+
|s|5 |
+-+--+
|a|10|
+-+--+
|y|1 |
+-+--+
|q|1 |
+-+--+
|u|1 |
+-+--+
|g|3 |
+-+--+
|m|1 |
+-+--+
|p|3 |
+-+--+
|r|2 |
+-+--+
|x|1 |
+-+--+
|c|1 |
+-+--+
|.|1 |
+-+--+
```
[Answer]
C#
```
string str = Console.ReadLine(); // Get Input From User Here
char chr;
for (int i = 0; i < 256; i++)
{
    chr = (char)i; // Use The Integer Index As ASCII Char Value --> Convert To Char
    if (str.IndexOf(chr) != -1) // If The Current Char Exists In The Input String
    {
        Console.WriteLine(chr + " : " + str.Count(x => x == chr)); // Count And Display
    }
}
Console.ReadLine(); // Hold The Program Open.
```
In Our Case, If The Input Will Be "**The definition of insanity is quoting the same phrase again and again and not expect despair.**"
The Output Will Be:
```
  : 15
. : 1
T : 1
a : 10
c : 1
d : 4
e : 8
f : 2
g : 3
h : 3
i : 10
m : 1
n : 10
o : 4
p : 3
q : 1
r : 2
s : 5
t : 6
u : 1
x : 1
y : 1
```
[Answer]
## C#: 129
This is Avivs answer but shorter:
```
var s=Console.ReadLine();for(int i=0;i<256;i++){var ch=(char)i;Console.Write(s.Contains(ch)?ch+":"+s.Count(c=>c==ch)+"\r\n":"");}
```
This is mine:
## C#: 103
```
foreach(var g in Console.ReadLine().OrderBy(o=>o).GroupBy(c=>c))Console.WriteLine(g.Key+":"+g.Count());
```
]